<?php
/**
* @package RecruitmentManager
* @version 1.5.2 Stable Update 1, August 2009
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * @package RecruitmentManagerHTML
 */
// This class takes care of the actual display of pages for the component.
class RecruitmentManagerHTML {
//
// Default function - Component front page (search functions, etc.)
//
  function mydefault() {
	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");
	$task 	= JRequest::getVar('task', '' ,"REQUEST");
	
	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our text paragraphs (New at 1.5.2. Used to be in global parameters.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
		$front_paragraph=$row['front_paragraph'];
		$front_paragraph2=$row['front_paragraph2'];
		$front_paragraph3=$row['front_paragraph3'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
		$front_paragraph='front_paragraph ' . JText::_('RAM_NOTFOUND');
		$front_paragraph2='front_paragraph2 ' . JText::_('RAM_NOTFOUND');
		$front_paragraph3='front_paragraph3 ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myemail=$user->get('email');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
	$myemail=$user->get('email');
?>

<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
//
// if user logged in, display links to stuff relevant to the user (interviews and such-like)
// otherwise just display the search form and top 5 jobs.
//
	if ($myuid > 0) {

	// see if a client record exists for this candidate
	$query="select * from ".$dbprefix."ram_clients where userid='$myuid' ";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a client record, create a candidate one
	if ($num_rows==0) {
		// see if a candidate record exists for this candidate
		$query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
		$sth=mysql_query($query);
		$num_rows = mysql_num_rows($sth);
		// if there is NOT a candidate record, create one
		if ($num_rows==0) {
			$query2="insert into ".$dbprefix."ram_candidates (userid, firstname, email) values ('$myuid', '$myrealname', '$myemail')";
			$sth2=mysql_query($query2);
			// check for any error
			if (mysql_error()) { // check for problem
				echo "<p class='error'><b>".JText::_('RAM_CANDCREATEERROR').":</b> </p>\n" . mysql_error();
			} else {
//				echo "<p>Candidate record with id '$myuid' created OK.</p>\n";
			}
		}

	   // get the candidates details
	   $query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
	   $sth=mysql_query($query);
	   $num_rows = mysql_num_rows($sth);
	   // if there is NOT a candidate record, display error
	   if ($num_rows==0) {
		echo "<p class='error'>".JText::_('RAM_CANDDETSFOR')." '$myuid' ".JText::_('RAM_NOTFOUND')."</p>\n";
	   } else {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$candid=$row['id'];
		$name=$row['firstname'] . ' ' . $row['surname'];
		// update their login record
		$cdate=date("Y-m-d H:i:s"); // format the current date/time
		$newlogins=$cdate . '<br />' . $row['logins']; // add timestamp to beginning of login record
		$query2="update ".$dbprefix."ram_candidates set logins='$newlogins' where userid=" . $userid;
		$sth2=mysql_query($query2); // fail silently
		$cv_adr1=$row['address1'];
		$cv_adr2=$row['address2'];
		$cv_postcode=$row['postcode'];
		$cv_area=$row['area'];
		$phone=$row['telephone'];
		$sendermail=$row['email'];
		$cv_dob=$row['birthdate'];
//		$cv_stat=$row['mstatus'];
//		$cv_children=$row['children'];
		$cv_education=$row['education'];
		$cv_workexp=$row['experience'];
		$cv_feducation=$row['courses'];
//		$cv_interests=$row['interests'];
		$cv_name=$row['cvurl'];
		$mobile=$row['mobile'];
		$sector=$row['sector'];
		// print message if no cv yet
		if (($cv_education=='') and ($cv_workexp=='') and ($cv_feducation=='') and ($cv_name=='')) {
?>

	<p class="RAM_Para">
	<?php echo JText::_('RAM_NOCV'); ?> <a href='index.php?option=com_recruitmentmanager&task=mydetails&Itemid=<?php echo $Itemid; ?>'><?php echo JText::_('RAM_NOCVLINK'); ?></a>.
	</p>

<?php
		}
?>

	<table align="center" cellspacing='3' cellpadding='5' width='100%'>
	<tr><th colspan="5" class='tablehead'><?php echo JText::_('RAM_NEWJOBS'); ?></th></tr>
	<tr>
		<th class="tablehead" width='150'><?php echo JText::_('RAM_POSITION'); ?></th>
		<th class="tablehead"><?php echo JText::_('RAM_AREA'); ?></th>
		<th class="tablehead"><?php echo JText::_('RAM_SALARYRANGE'); ?></th>
		<th class="tablehead" colspan='2'><?php echo JText::_('RAM_ACTION'); ?></th>
	</tr>
<?php
	$query="select * from ".$dbprefix."ram_jobs where jobfilled='n' and approved='y' and sector='$sector' and area='$cv_area' order by id desc";
//	print "<p>SQL: $query</p>\n";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	$rowcolor='even';
	$jobsfound=0;
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$query2="select id from ".$dbprefix."ram_applications where jobid=" . $row['id'] . " and userid='$myuid' order by id desc";
			$sth2=mysql_query($query2) or die( JText::_('') . ': ' . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			if ($num_rows2>0) {
				// ignore, job already applied for
			} else {
?>
	<tr class='<?php echo $rowcolor; ?>'>
<?php
				$jobsfound++;
				print "<td class='$rowcolor'>" .  $row['jobtitle'] . "</td>";
				// get area details
				$query2="select * from ".$dbprefix."ram_areas WHERE id = '".$row['area']."' ";
				$sth2=mysql_query($query2);
				$num_rows2 = mysql_num_rows($sth2);
				// record found?
				if ($num_rows2>0) {
					$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
					$Country=$row2['Country'];
					$County=$row2['County'];
					$Area="$Country, $County";
				} else {
					$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
				} // eof check for record found
				// get rate band details
				$query2="select * from ".$dbprefix."ram_ratebands  WHERE id = '".$row['salaryrange']."' ";
				$sth2=mysql_query($query2);
				$num_rows2 = mysql_num_rows($sth2);
				// record found?
				if ($num_rows2>0) {
					$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
					$RateBand=$row2['desc'];
				} else {
					$RateBand=JText::_('RAM_RATEBAND') . ' ' . JText::_('RAM_NOTFOUND');
				} // eof check for record found
?>
		<td><?php echo $Area; ?></td>
		<td><?php echo $RateBand; ?></td>
		<td><a href="index.php?option=com_recruitmentmanager&amp;task=display&amp;jid=<?php echo $row['id'] . "&amp;uid=$myuid&Itemid=$Itemid"; ?>"><?php echo JText::_('RAM_DETAILS'); ?></a></td>
		<td><a href="index.php?option=com_recruitmentmanager&amp;task=apply&amp;jid=<?php echo $row['id'] . "&amp;uid=$myuid&Itemid=$Itemid"; ?>"><?php echo JText::_('RAM_APPLY'); ?></a></td>
	</tr>
<?php
				if ($rowcolor==='even') { $rowcolor='odd'; } else { $rowcolor='even'; }
			}

		} // eof while loop

		// check if some jobs found
		if (!$jobsfound) {
			print "<tr><td align='center' class='$rowcolor' colspan='5'>" . JText::_('RAM_NONEWJOBS') . "</td></tr>\n";
		}

	} else {

		print "<tr><td align='center' class='$rowcolor' colspan='5'>" . JText::_('RAM_NONEWJOBS') . "</td></tr>\n";

	}

?>
</table>

<br /><br />

<table align="center" cellspacing='1' cellpadding='0' width='100%'>
<tr><th colspan="5" class='tablehead'><?php echo JText::_('RAM_INTAPPS'); ?></th></tr>
<tr>
	<th width='120' height="18" class="tablehead"><?php echo JText::_('RAM_DATETIME'); ?></th>
	<th class="tablehead"><?php echo JText::_('RAM_JOBREF'); ?></th>
	<th class="tablehead" width='150'><?php echo JText::_('RAM_POSITION'); ?></th>
	<th class="tablehead"><?php echo JText::_('RAM_LOCATION'); ?></th>
	<th align="center"  class="tablehead"><?php echo JText::_('RAM_STATUS'); ?></th>
</tr>

<?php
	$query="select * from ".$dbprefix."ram_interviews where candid='$candid' order by id desc";
//	print "<p>SQL: $query</p>\n";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	$rowcolor='even';
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			print "<tr class='$rowcolor'><td>" .  $row['date'] . ' ' .  substr($row['time'],0,5) . "</td>";
			$query2="select * from ".$dbprefix."ram_jobs where id=" . $row['jobid'];
			//print "<p>SQL: $query2</p>\n";
			$sth2=mysql_query($query2) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$jobref=$row2['jobref'];
				$jobtitle=$row2['jobtitle'];
			} else {
				$jobref='';
				$jobtitle=JText::_('RAM_CLOSED');
			}
			print "<td>" . $jobref . "</td>";
			print "<td>" . $jobtitle . "</td>";
			print "<td>" . $row['location'] . "</td>";
			print "<td>" .  JText::_('RAM_INTSTATUS'.$row['status']) . "</td>";
			print "</tr>\n";
			if ($rowcolor=='even') { $rowcolor='odd'; } else { $rowcolor='even'; }
		}
	} else {
		print "<tr><td align='center' class='$rowcolor' colspan='5'>" . JText::_('RAM_NOINTERVIEWS') . "</td></tr>\n";
	}

?>
</table>

<br /><br />

<table align="center" cellspacing='3' cellpadding='5' width='100%'>
<tr><th colspan="5" class='tablehead'><?php echo JText::_('RAM_APPHIST'); ?></th></tr>
<tr>
	<th class="tablehead" width='80'><?php echo JText::_('RAM_DATE'); ?></th>
	<th class="tablehead"><?php echo JText::_('RAM_JOBREF'); ?></th>
	<th class="tablehead" width='150'><?php echo JText::_('RAM_POSITION'); ?></th>
	<th align="center"  class="tablehead"><?php echo JText::_('RAM_STATUS'); ?></th>
	<th class="tablehead"><?php echo JText::_('RAM_ACTION'); ?></th>
</tr>
<?php
	$query="select * from ".$dbprefix."ram_applications where userid='$myuid' order by id desc";
//	print "<p>SQL: $query</p>\n";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	$rowcolor='even';
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			print "<tr class='$rowcolor'><td>" .  $row['date'] . "</td>";
			$query2="select * from ".$dbprefix."ram_jobs where id=" . $row['jobid'];
			//print "<p>SQL: $query2</p>\n";
			$sth2=mysql_query($query2) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$jobref=$row2['jobref'];
				$jobtitle=$row2['jobtitle'];
			} else {
				$jobref='';
				$jobtitle=JText::_('RAM_CLOSED');
			}
			print "<td>" . $jobref . "</td>";
			print "<td>" . $jobtitle . "</td>";
			print "<td>" . JText::_('RAM_APPSTATUS'.$row['status']) . "</td>";
?>
		<td class='<?php echo $rowcolor; ?>' align='center'><a href="index.php?option=com_recruitmentmanager&amp;task=display&amp;jid=<?php echo $row['jobid'] . "&amp;uid=$myuid&Itemid=$Itemid"; ?>"><?php echo JText::_('RAM_DETAILS'); ?></a></td>
<?php
			print "</tr>\n";
			if ($rowcolor=='even') { $rowcolor='odd'; } else { $rowcolor='even'; }
		}
	} else {
		print "<tr><td align='center' class='$rowcolor' colspan='5'>" . JText::_('RAM_NOAPPSFOUND') . "</td></tr>\n";
	}

?>
</table>

<br /><br />

<hr />

<?php

	   } // eof candidate found check

	} else { // they are a client!
		// ERROR MSG NOT REQD ON THIS PAGE!
//		echo "<p class='error'>".JText::_('RAM_REGASCLIENT')."</p>\n";
	} // eof check for client record

	} // eof check for user logged in

//
// ================ now display stuff for all visitors (search form, etc.) =================
//
?>


<!--  <p class="RAM_Para"><?php echo $front_paragraph2; ?></p>-->

<?php
	if (isset($_POST['search']) || $task == 'search') {
?>
	<div class="article">
		<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_SEARCHHEAD2'); ?></h2>
	</div>
<?php
		$limit      = JRequest::getVar('limit' , 25);
	    $limitstart = JRequest::getVar('limitstart', 0);
	    $jobref = JRequest::getVar('jobref', '' ,"POST", 'STRING');
	    $jobtype = JRequest::getVar('jobtype', '' ,"POST", 'STRING');
	    
	    $session = JFactory::getSession();
	    if (isset($_POST['search'])) {
			$searchfor = JRequest::getVar('searchfor', '' ,"POST", 'STRING');
			$sector = JRequest::getVar('sector', '' ,"POST", 'STRING');
			$area = JRequest::getVar('area', '' ,"POST", 'STRING');
			$salary = JRequest::getVar('salary', '' ,"POST", 'STRING');
	   	
			$searchArr = array(
				'searchfor' => $searchfor,
				'sector' => $sector,
				'area' => $area,
				'salary' => $salary,
			);
			
			$session->set('isSearch', $searchArr);
	   	} else {
	   		$dataSearch = $session->get('isSearch');
		   	if(is_array($dataSearch)) {
				$searchfor = isset($dataSearch['searchfor'])?$dataSearch['searchfor']:'';
				$sector = isset($dataSearch['sector'])?$dataSearch['sector']:'';
				$area = isset($dataSearch['area'])?$dataSearch['area']:'';
				$salary = isset($dataSearch['salary'])?$dataSearch['salary']:'';
			} else {
				$searchfor = JRequest::getVar('searchfor', '' ,"POST", 'STRING');
				$sector = JRequest::getVar('sector', '' ,"POST", 'STRING');
				$area = JRequest::getVar('area', '' ,"POST", 'STRING');
				$salary = JRequest::getVar('salary', '' ,"POST", 'STRING');
			}
	   	}
	   	
		$cond = '';
		$condLimit = " Limit $limitstart, $limit";
		
		$query="select * from ".$dbprefix."ram_jobs where jobfilled='n' and approved='y' ";
		// search for jobref?
		if ($jobref==='') { // no, build a query from the supplied criteria

			$fuzzy="'%" . addslashes($searchfor) . "%'";
			$cond.=" and (jobdesc like $fuzzy or jobtitle like $fuzzy or sector like $fuzzy or area like $fuzzy )";

			if ( ($sector!=='') and ($sector!=='All') ) {
				$cond.=" and sector = '" . addslashes($sector) . "'";
			}
			if ( ($area!=='') and ($area!=='All') ) {
				$cond.=" and area = '" . addslashes($area) . "'";
			}
			if ( ($salary!=='') and ($salary!=='All') ) {
				$cond.=" and salaryrange = '" . addslashes($salary) . "'";
			}
			if ( ($jobtype!=='') and ($jobtype!=='All') ) {
				$cond.=" and jobtype = '" . addslashes($jobtype) . "'";
			}
		} else { // yes
			$cond .=" and jobref = '" . addslashes($jobref) . "'";
		}// desc limit " . $tmp . ", 5

		$cond.=" order by id desc";

		$db->setQuery( $query . $cond . $condLimit); 
		$sth = $db->loadAssocList(); 
		$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
		$rowcolor='even';

	    $query="select count(*) as count from ".$dbprefix."ram_jobs where jobfilled='n' and approved='y' ";
		$db->setQuery( $query . $cond );
		$db->query();
		$totalAll = $db->loadResult();

	    // include a pagination library
        jimport('joomla.html.pagination');
        $pagination = new JPagination($totalAll, $limitstart, $limit);
        
        
		if ($num_rows>0) {
?>

	<p style="padding-left:25px;padding-bottom:10px"><?php echo JText::_('RAM_SEARCHPARA'); ?></p>
	<div class="vacancies-list">
	<table  width="100%" cellspacing='1' cellpadding='1'>
	<tr>
		<!--<th><?php echo JText::_('RAM_JOBREF'); ?></td>-->
		<th><?php echo JText::_('RAM_JOBTITLE') . ' / ' . JText::_('RAM_JOBTYPELABEL'); ?></th>
		<th><?php echo JText::_('RAM_AREA'); ?></th>
		<th><?php echo JText::_('RAM_POSTED'); ?></th>
		<th><?php echo JText::_('RAM_ACTION'); ?></th>
	</tr>
<?php
			// read thru the records (now in an array)
			$rownum=0;
//			while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			while ($row=$sth[$rownum]) {
				$tmp='';
				if ($row['jobtype']==='1') { $tmp=JText::_('RAM_JOBTYPE1'); }
				if ($row['jobtype']==='2') { $tmp=JText::_('RAM_JOBTYPE2'); }
				if ($row['jobtype']==='3') { $tmp=JText::_('RAM_JOBTYPE3'); }
				if ($row['jobtype']==='4') { $tmp=JText::_('RAM_JOBTYPE4'); }

				$num_rows3=0; // default to no recs found
				// only check for applications if there's a logged in user
				if ($myuid>0) {
					$query3="select id from ".$dbprefix."ram_applications where jobid=" . $row['id'] . " and userid='$myuid' ";
					$sth3=mysql_query($query3);
					$num_rows3 = mysql_num_rows($sth3);
				}
				if ($num_rows3>0) {
					// job already applied for, don't display
				} else {
					// no job application, display it
?>
	<tr class="<?php echo $rowcolor; ?>">
		<!--<td><?php echo $row['jobref']; ?></td>-->
		<td>
			<?php echo '<b>' . $row['jobtitle'] . "</b><br />\n" . $tmp; ?>
		</td>
		<td><?php 
				// get area details
				$query2="select * from ".$dbprefix."ram_areas WHERE id = '".$row['area']."' ";
				$sth2=mysql_query($query2);
				$num_rows2 = mysql_num_rows($sth2);
				// record found?
				if ($num_rows2>0) {
					$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
					$Country=$row2['Country'];
					$County=$row2['County'];
					$Area="$Country, $County";
				} else {
					$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
				} // eof check for record found
				echo $Area; 
		?></td>
		<td><?php echo $row['dateposted']; ?></td>
		<td  colspan="2">
			<a class="btn-detail" href="<?php echo JRoute::_( 'index.php?option=com_recruitmentmanager&amp;task=display&amp;jid='.$row['id'].'&uid='.$myuid.'&search=1&Itemid=18');?>"><?php echo JText::_('RAM_DETAILS'); ?></a>
			<a class="btn-apply" href="<?php echo JRoute::_( 'index.php?option=com_recruitmentmanager&amp;task=apply&amp;jid='.$row['id'] .'&uid='.$myuid.'&Itemid=18');?>"><?php echo JText::_('RAM_APPLY'); ?></a>
		</td>
	</tr>
<?php
					if ($rowcolor==='even') { $rowcolor='odd'; } else { $rowcolor='even'; }

				} // eof check for job application

				$rownum++; // go to the next record

			} // eof while loop
?>
	</table>
</div>
<br />
<?php echo $pagination->getListFooter();?>
<?php
		} else {
?>

			<p class='error' style="padding-left:25px"><?php echo JText::_('RAM_SEARCHERROR1'); ?></p>

<?php
			return;
		}  
?>

	<p style="padding-left:25px"><?php echo $front_paragraph3; ?></p>

<?php
		return;
	} // eof check for search request

?>



	

<?php
	//
	// only display latest jobs if not searching or applying, etc.
	//
	if ( (!isset($_GET['jid'])) and (!isset($_POST['search'])) ) {

	$limit      = JRequest::getVar('limit' , 25);
    $limitstart = JRequest::getVar('limitstart', 0);
	    
	$query="select count(*) as count from ".$dbprefix."ram_jobs where jobfilled='n' and top5='y' and approved='y' and enable='1'";
	$db->setQuery( $query );
	$db->query();
	$totalAll = $db->loadResult();

	// only display jobs with top5 indicator set now. Also have to be approved now.
	$query="select * from ".$dbprefix."ram_jobs where jobfilled='n' and top5='y' and approved='y' and enable='1' order by dateposted desc Limit $limitstart, $limit";
	//print "<p>SQL: $query</p>\n"; . $row['id'] . '&uid=' . $userid .
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	$rowcolor='even';
	if ($num_rows>0) {
//echo $num_rows;

	    // include a pagination library
        jimport('joomla.html.pagination');
        $pagination = new JPagination($totalAll, $limitstart, $limit);

?>

	<!--<h2 class="RAM_SubHeading"><b><?php echo JText::_('RAM_TOP5HEAD'); ?></b></h2>-->
    <div class="article">
    	<?php echo JText::_('RAM_TOP5HEAD2'); ?>
    </div>
	<div class="vacancies-list">
    <table width="100%" cellspacing="1" cellpadding="1" border="0">
	<tr>
		<th><?php echo JText::_('RAM_JOBTITLE') . ' / ' . JText::_('RAM_JOBTYPELABEL'); ?></td>
     	<th><?php echo JText::_('RAM_AREA'); ?></td>
		<th><?php echo JText::_('RAM_POSTED'); ?></td>
<?php
if ($show_ratebands) { // see if should show the rate bands
?>
		<th><?php echo JText::_('RAM_SALARYRANGE'); ?></td>
<?php
} // eof rate band check
?>	  	</tr>
<?php
		// read thru the records (now in an array)
		$rownum=0;
//		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
		while ($row=$sth[$rownum]) {
			$tmp='';
			if ($row['jobtype']==='1') { $tmp=JText::_('RAM_JOBTYPE1'); }
			if ($row['jobtype']==='2') { $tmp=JText::_('RAM_JOBTYPE2'); }
			if ($row['jobtype']==='3') { $tmp=JText::_('RAM_JOBTYPE3'); }
			if ($row['jobtype']==='4') { $tmp=JText::_('RAM_JOBTYPE4'); }
?>
	<tr class="<?php echo $rowcolor; ?>">
		<td width="320">
			<p>
				<a href="index.php?option=com_recruitmentmanager&amp;task=display&amp;jid=<?php echo $row['id'] . "&amp;uid=$myuid&Itemid=$Itemid"; ?>"><?php echo '<b>' . $row['jobtitle'] . "</b><br />\n" . $tmp; ?></a>
			</p>		
		<?php 
			// get area details
			$query3="select * from ".$dbprefix."ram_clients WHERE id = '".$row['company']."' ";
			$sth3=mysql_query($query3);
			$num_rows3 = mysql_num_rows($sth3);
			// record found?
			if ($num_rows3>0) {
				$row3=mysql_fetch_array($sth3, MYSQL_ASSOC);
				$clientname =$row3['clientname'];
			} else {
				$clientname =JText::_('RAM_COMPANY') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found

			echo $clientname; 
?>
      </td>
	  <td>
<?php 
			// get area details
			$query2="select * from ".$dbprefix."ram_areas WHERE id = '".$row['area']."' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$Country=$row2['Country'];
				$County=$row2['County'];
				$Area="$Country, $County";
			} else {
				$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found

			echo $Area; 
?>		</td>
		<td><?php echo $row['dateposted']; ?></td>
<?php
if ($show_ratebands) { // see if should show the rate bands
?>
		<td>
<?php 
			// get rate band details
			$query2="select * from ".$dbprefix."ram_ratebands  WHERE id = '".$row['salaryrange']."' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$RateBand=$row2['desc'];
			} else {
				$RateBand=JText::_('RAM_RATEBAND') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found
			echo $RateBand; 
?>		</td>
<?php
} // eof rate band check
?>
		</tr>
<?php
			if ($rowcolor==='even') { $rowcolor='odd'; } else { $rowcolor='even'; }

			$rownum++; // go to the next record

		} // eof while
?>
	</table>
	</div>
<br />
<?php echo $pagination->getListFooter();?>

<?php
	} else {
?>
		<!--p><?php echo JText::_('RAM_NOJOBS'); ?></p-->
<?php
	} // eof check for jobs found

	} // eof search or apply check

	_myfooter($show_poweredby);

  } // eof default function

//
// Candidate Details function
//
  function mydetails() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$notify_email = $params->get('notify_email', ''); // default is none
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_MYDETAILS'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
	$myemail=$user->get('email');
?>

<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting

	// check the user is logged in!
	if ($myuid > 0) {

	// see if a client record exists for this candidate
	$query="select * from ".$dbprefix."ram_clients where userid='$myuid' ";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a client record, create a candidate one
	if ($num_rows==0) {
		// see if a candidate record exists for this candidate
		$query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
		$sth=mysql_query($query);
		$num_rows = mysql_num_rows($sth);
		// if there is NOT a candidate record, create one (if not one already)
		if ($num_rows==0) {
			$query2="insert into ".$dbprefix."ram_candidates (userid, firstname, email) values ('$myuid', '$myrealname', '$myemail')";
			$sth2=mysql_query($query2);
			// check for any error
			if (mysql_error()) { // check for problem
				echo "<p class='error'><b>".JText::_('RAM_CANDCREATEERROR').":</b> </p>\n" . mysql_error();
			} else {
	//			echo "<p>Candidate record with id '$myuid' created OK.</p>\n";
			}
		}
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_CANDDETSHEAD'); ?></h2>

	<p class="RAM_Para"><?php echo JText::_('RAM_BACK'); ?> <a href="<?php echo JRoute::_( "index.php?option=com_recruitmentmanager&task=&Itemid=$Itemid" ); ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
   // see if candidate form submitted
   if (isset($_POST["submit"])) {

	// yes, so get the form values
	$firstname=JRequest::getVar('firstname', '' ,"POST", 'STRING');
	$surname=JRequest::getVar('surname', '' ,"POST", 'STRING');
	$cv_adr1=JRequest::getVar('cv_adr1', '' ,"POST", 'STRING');
	$cv_adr2=JRequest::getVar('cv_adr2', '' ,"POST", 'STRING');
	$cv_postcode=JRequest::getVar('cv_postcode', '' ,"POST", 'STRING');
	$cv_area=JRequest::getVar('cv_area', '' ,"POST", 'STRING');
	$phone=JRequest::getVar('phone', '' ,"POST", 'STRING');
	$cv_dob=JRequest::getVar('cv_dob', '' ,"POST", 'STRING');
//	$cv_stat=JRequest::getVar('cv_stat', '' ,"POST", 'STRING');
//	$cv_children=JRequest::getVar('cv_children', '' ,"POST", 'STRING');
	$cv_education=JRequest::getVar('cv_education', '' ,"POST", 'STRING', 4);
	$cv_workexp=JRequest::getVar('cv_workexp', '' ,"POST", 'STRING', 4);
	$cv_feducation=JRequest::getVar('cv_feducation', '' ,"POST", 'STRING', 4);
	$cv_interests=JRequest::getVar('cv_interests', '' ,"POST", 'STRING', 4);
	// check for updated cv
	if (isset($_FILES['cv']['name'])) {
		if ($_FILES['cv']['name']!=='') {
			$att=$_FILES['cv']['name']; // store for sql command below
		} else {
			$att=JRequest::getVar('curr_cv', '' ,"POST", 'STRING'); // store for sql command below
		}
	} else {
		$att=JRequest::getVar('curr_cv', '' ,"POST", 'STRING'); // store for sql command below
	}
	$mobile=JRequest::getVar('mobile', '' ,"POST", 'STRING');
	$sector=JRequest::getVar('sector', '' ,"POST", 'STRING');

	$uid = JRequest::getVar('uid', '0' ,"POST", 'INTEGER');

	$query="update ".$dbprefix."ram_candidates set firstname='" . addslashes($firstname) . "', surname='" . addslashes($surname) . "', address1='" . addslashes($cv_adr1) . "', address2='" . addslashes($cv_adr2) . "', postcode='" . addslashes($cv_postcode) . "', area='" . addslashes($cv_area) . "', telephone='" . addslashes($phone) . "', birthdate='" . addslashes($cv_dob) . "', cvurl='" . addslashes($att) . "', mobile='" . addslashes($mobile) . "', sector='" . addslashes($sector) . "', education='" . addslashes($cv_education) . "',  experience='" . addslashes($cv_workexp) . "', courses='" . addslashes($cv_feducation) . "', interests='" . addslashes($cv_interests) . "', fullname='" . addslashes($firstname) . ' ' . addslashes($surname) . "' where id = '$uid' ";

	$sth=mysql_query($query) or die("Update failed: " . mysql_error() . "<br>SQL = " . $query);

	// confirm record update
	$query="select id from ".$dbprefix."ram_candidates where firstname='" . addslashes($firstname) . "' and surname='" . addslashes($surname) . "' and area='" . addslashes($cv_area) . "' and postcode='" . addslashes($cv_postcode) . "'";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	$status='';
	// if there is NOT a record, display error
	if ($num_rows==0) {
		echo "<p class='error'>".JText::_('RAM_CANDSAVEERROR')."</p>\n";
	} else {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);

		echo "<p class='RAM_Para'>".JText::_('RAM_CANDSAVEOK')."</p>\n";

		// send the admin an email notification of this submission
		$header="From: noreply@".str_replace('www.', '', $_SERVER["HTTP_HOST"])."\r\n";
		$header.="MIME-Version: 1.0\r\n";
		$header.="Content-Type: multipart/mixed; boundary=\"JMRAM-12345\"; charset='utf-8'\r\n";
		$header.="Content-Transfer-Encoding: 7bit\r\n";
		$header .= JText::_('RAM_MAILUPGRADE') . "\r\n";
		$message="--JMRAM-12345\r\n";
		$message.="Content-Type: text/plain;\r\n";
		$message.="Content-Transfer-Encoding: 7bit\r\n";
		$message .= "\r\n" . JText::_('RAM_CANDMAILMSG0') . "\n\n" . JText::_('RAM_CANDMAILMSG1') . ":- '$firstname $surname' " . JText::_('RAM_CANDMAILMSG2') . ":-  '$myusername'.\r\n";
		// check for attachment (cv)
		if (isset($_FILES['cv']['name'])) {
		   if ($_FILES['cv']['name']!=='') {
			$cv_name=$_FILES['cv']['name']; // store for later
			$tmp = strtolower($cv_name);
			// check valid file type
			if ( (strpos($tmp, 'odt')) or (strpos($tmp, 'doc')) or (strpos($tmp, 'rtf')) or (strpos($tmp, 'pdf')) or (strpos($tmp, 'txt')) ) {
				// add seperator
				$message.="--JMRAM-12345\r\n";
				// get the attachment data and encode it
				$fd=fopen ($_FILES['cv']['tmp_name'], "r");
				$FileContent=fread($fd,filesize($_FILES['cv']['tmp_name']));
				fclose ($fd);
				$att=chunk_split(base64_encode($FileContent));
				$message.="Content-Type: " . $_FILES['cv']['type'] . "; name=\"" . $_FILES['cv']['name'] . "\"\r\n";
				$message.="Content-Transfer-Encoding: base64\r\n";
				$message.="Content-Disposition: attachment\r\n";
				$message.= "\r\n";
				$message.="$att\r\n"; // attachment data
				$message.= "\r\n\r\n";
				$message.="--JMRAM-12345--\r\n";
				//
				// now copy it to the server for storage (New at 1.5.2)
				// first, create cvs folder if it doesn't exist
				$cvfolder = dirname(__FILE__)."/cvs";
//				echo "<p>cvfolder = $cvfolder</p>\n"; // debugging only
				if (!file_exists($cvfolder)) {
					$res=mkdir($cvfolder, 0777);
				} else {
					$res=chmod($cvfolder, 0777);
				}
				// now create users folder if it doesn't exist
				$userfolder = "$cvfolder/$myuid";
//				echo "<p>userfolder = $userfolder</p>\n"; // debugging only
				if (!file_exists($userfolder)) {
					$res=mkdir($userfolder, 0777);
				} else {
					$res=chmod($userfolder, 0777);
				}
				// now build the filename and MOVE it to it's destination
				$uploadfile = "$userfolder/$cv_name";
				if (move_uploaded_file($_FILES["cv"]['tmp_name'], $uploadfile)) {
//					echo "<p>Stored uploaded file to:- $uploadfile</p>\n"; // debugging only
					echo "<p class='RAM_Para'>" . JText::_('RAM_CVUPLOADED') . "</p>\n";
				}

			} else {

				$att=''; // invalid type
				echo "<p class='error'>" . JText::_('RAM_INVFILETYPE') . ":- " . $_FILES['cv']['type'] . ". It has been ignored.</p>\n";

			} // eof check for valid file type

		   } else {

			$att='';
			$message.="--JMRAM-12345--\r\n";

		   } // eof check for non null filename

		} else {

			$att='';
			$message.="--JMRAM-12345--\r\n";

		} // eof check for attachment

		$subject=JText::_('RAM_CANDMAILSUBJECT');

		// only send nofification if email address supplied
		if ($notify_email!='') {
//			echo "<p>message = $message</p>\n"; // debugging only
			$res=mail($notify_email, $subject, $message, $header);
			if ($res) {
//				echo "<p>Email nofification sent to $notify_email.</p>";
			} else {
				echo "<p class='error'>".JText::_('RAM_EMAILERROR')."</p>";
			}
		} // eof check for email address

	} // eof save check

   } //eof submit check

//
// display Candidate Details
//
	$query="select * from ".$dbprefix."ram_candidates where userid='$myuid' ";
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// if there is NOT a record, display error
	if ($num_rows==0) {
		echo "<p class='error'>" . JText::_('RAM_CANDDETSNOTFND') . "</p>\n";
		echo "<p class='RAM_Para'><a href='javascript:history.back()'>" . JText::_('RAM_BACKPREV') . "</a></p>\n";
	} else {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$candid=$row['id'];
		$firstname=$row['firstname'];
		$surname=$row['surname'];
		$username=$row['username'];
		$password=$row['password'];
		$cv_adr1=$row['address1'];
		$cv_adr2=$row['address2'];
		$cv_postcode=$row['postcode'];
		$cv_area=$row['area'];
		$phone=$row['telephone'];
		$sendermail=$row['email'];
		$cv_dob=$row['birthdate'];
		$cv_stat=$row['mstatus'];
		$cv_children=$row['children'];
		$cv_education=$row['education'];
		$cv_workexp=$row['experience'];
		$cv_feducation=$row['courses'];
		$cv_interests=$row['interests'];
		$cv_name=$row['cvurl'];
		$mobile=$row['mobile'];
		$sector=$row['sector'];
	}

?>

<form class="apply-form" action="index.php" onsubmit="return checkForm()" method="post" enctype="multipart/form-data" name="candForm">

<input name="task" type="hidden" id="task" value="mydetails" />
<input type="hidden" name="option" value="com_recruitmentmanager" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

<table align="center" border="0" width="100%" cellpadding="0" cellspacing="1">
<tr><th class="tablehead" colspan="2"><?php echo JText::_('RAM_PERSHEAD'); ?></th></tr>
<tr>
	<td class="rowcolor2" width="25%"><b><?php echo JText::_('RAM_CANDFNAME'); ?>:</td>
	<td class="rowcolor2" width="75%"><input name="firstname" type="text" value="<?php echo $firstname; ?>" size="25" maxlength="32" /></td>
</tr><tr>
	<td class="rowcolor1"><b><?php echo JText::_('RAM_CANDLNAME'); ?>:</td>
	<td class="rowcolor1"><input name="surname" type="text" value="<?php echo $surname; ?>" size="25" maxlength="32" /></td>
</tr><tr>
	<td class="rowcolor2" colspan="2">
	<b><?php echo JText::_('RAM_CANDADDR'); ?>:</b><br />
	<input type="text" name="cv_adr1" value="<?php echo $cv_adr1; ?>" size="50" maxlength="128" /><br />
	<input type="text" name="cv_adr2" value="<?php echo $cv_adr2; ?>" size="50" maxlength="128" /></td>
</tr><tr>
	<td class="rowcolor1"><b><?php echo JText::_('RAM_CANDPOSTCODE'); ?>: </b></td>
	<td class="rowcolor1"><input type="text" name="cv_postcode" value="<?php echo $cv_postcode; ?>" size="12" maxlength="20" /></td>
</tr><tr>
	<td class="rowcolor2" valign="top"><b><?php echo JText::_('RAM_AREA'); ?>: </b></td>
	<td class="rowcolor2"><select name="cv_area">
	<option value="" <?php if ($cv_area==='') { echo 'selected'; } ?> ><?php echo JText::_('RAM_SELECTAREA'); ?></option>
<?php
	// get list of areas
	$query="select * from ".$dbprefix."ram_areas order by Country, County asc";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$aid=$row['id'];
			$Country=$row['Country'];
			$County=$row['County'];
			$selind='';
			if ($cv_area==$aid) { $selind='selected'; }
			echo "		<option value='$aid' $selind >$Country, $County</option>";
		} // eof while loop
	} // eof check for records found
?>
	</select>
	</td>
</tr><tr>
	<td class="rowcolor1"><b><?php echo JText::_('RAM_CANDTELNO'); ?>:</b></td>
	<td class="rowcolor1"><input type="text" name="phone" value="<?php echo $phone; ?>" size="15" maxlength="40" /></td>
</tr><tr>
	<td class="rowcolor2"><b><?php echo JText::_('RAM_CANDMOBILE'); ?>:</b></td>
	<td class="rowcolor2"><input type="text" name="mobile" value="<?php echo $mobile; ?>" size="15" maxlength="40" /></td>
</tr><tr>
	<td class="rowcolor1"><b><?php echo JText::_('RAM_CANDDOB'); ?>:</b></td>
	<td class="rowcolor1">
<?php 
// yes, output our date field and picker
echo JHTML::_( 'calendar', $cv_dob, "cv_dob", "cv_dob", '%Y-%m-%d', ' size="10" maxlength="10" title="Click on the icon to choose a date" READONLY ');
?>
    (<?php echo JText::_('RAM_CANDDATEFORMAT'); ?>)
</td>
</tr><!--tr>
	<td class="rowcolor2"><b>Marital status:</b></td>
	<td class="rowcolor2"><select name="cv_stat">
	<option value="Not stated" <?php if ($cv_stat==='Not stated') { echo 'selected'; } ?> >Please select</option>
          <option value="Cohabitant" <?php if ($cv_stat==='Cohabitant') { echo 'selected'; } ?> >Cohabitant</option>
          <option value="Divorced" <?php if ($cv_stat==='Divorced') { echo 'selected'; } ?> >Divorced</option>
          <option value="Married" <?php if ($cv_stat==='Married') { echo 'selected'; } ?> >Married</option>
          <option value="Single" <?php if ($cv_stat==='Single') { echo 'selected'; } ?> >Single</option>
          <option value="Unmarried" <?php if ($cv_stat==='Unmarried') { echo 'selected'; } ?> >Unmarried</option>
</select></td>
</tr><tr>
	<td class="rowcolor1"><b>Number of children:</b></td>
	<td class="rowcolor1"><input type="text" name="cv_children" value="<?php echo $cv_children; ?>" size="10" maxlength="20" /></td>
</tr--><tr>
	<td class="rowcolor2"><b><?php echo JText::_('RAM_CANDSECTOR'); ?>:</b></td>
	<td class="rowcolor2"><select name="sector">
         	<option value="" <?php if ($sector==='') { echo 'selected'; } ?> ><?php echo JText::_('RAM_SELECTSECTOR'); ?></option>
<?php
	// get list of sectors
	$query="select * from ".$dbprefix."ram_sectors order by `desc` asc";
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		// read thru the records (now in an array)
		$rownum=0;
//		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
		while ($row=$sth[$rownum]) {
			$sid=$row['id'];
			$desc=$row['desc'];
			$selind='';
			if ($sector==$sid) { $selind='selected'; }
			echo "		<option value='$sid' $selind >$desc</option>";
			$rownum++; // go to the next record
		} // eof while loop
	} // eof check for records found
?>
		</select>
	</td>
</tr><tr>
	<td class="rowcolor1">

		<b><?php echo JText::_('RAM_CANDEDUC'); ?>:</b>
	</td>
	<td class="rowcolor1">
<?php
$editor =& JFactory::getEditor();
echo $editor->display('cv_education', $cv_education, '400', '200', '40', '5', false);
?>
	</td>
</tr><tr>
	<td class="rowcolor2">
		<b><?php echo JText::_('RAM_CANDWORKEXP'); ?>:</b>
	</td>
	<td class="rowcolor2">
<?php
$editor =& JFactory::getEditor();
echo $editor->display('cv_workexp', $cv_workexp, '400', '200', '40', '5', false);
?>
	</td>
</tr><tr>
	<td class="rowcolor1">
		<b><?php echo JText::_('RAM_CANDFE'); ?>:</b>
	</td>
	<td class="rowcolor1">
<?php
$editor =& JFactory::getEditor();
echo $editor->display('cv_feducation', $cv_feducation, '400', '200', '40', '5', false);
?>
	</td>
</tr><tr>
	<td class="rowcolor2">
		<b><?php echo JText::_('RAM_CANDINTER'); ?>:</b>
	</td>
	<td class="rowcolor2">
<?php
$editor =& JFactory::getEditor();
echo $editor->display('cv_interests', $cv_interests, '400', '200', '40', '5', false);
?>
	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

		<p class='RAM_Para'><b><?php echo JText::_('RAM_UPCV'); ?>:</b> 
<?php 
	$uploadfile = "$myuid/$cv_name";
	echo '<a target="_blank" title="' . JText::_('RAM_DOWNLOADCV') . '" href="components/com_recruitmentmanager/cvs/' . $uploadfile . '">' . "$cv_name</a>"; 
?>
		 <input type="hidden" name="curr_cv" value="<?php echo $cv_name; ?>" /></p>
	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">

	<p class='RAM_Para'><b><?php echo JText::_('RAM_CVHELP'); ?></b></p>

	<p class='RAM_Para'><b><?php echo JText::_('RAM_CVSUPP'); ?></p>

	<p class='RAM_Para'><b><?php echo JText::_('RAM_CHOOSE'); ?>:</b> <input type="file" name="cv" /></p>

	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">
	<input type="hidden" name="uid" value="<?php echo $candid; ?>" />
	<input type="reset" value="<?php echo JText::_('RAM_RESET'); ?>" name="reset" />
	<input type="submit" value="<?php echo JText::_('RAM_SAVEDETS'); ?>" name="submit" />
	</td>

</tr></table>

</form>

<script>
<!--

// validate form fields before submitting
function checkForm() {

if (document.candForm.firstname.value=='') {
	alert("<?php echo JText::_('RAM_JSFNERROR'); ?>");
	return false;
}

if (document.candForm.surname.value=='') {
	alert("<?php echo JText::_('RAM_JSSNERROR'); ?>!");
	return false;
}

if (document.candForm.phone.value=='') {
	alert("<?php echo JText::_('RAM_JSPHONEERROR'); ?>");
	return false;
}

if (document.candForm.cv_area.selectedIndex==0) {
	alert("<?php echo JText::_('RAM_JSAREAERROR'); ?>");
	return false;
}

if (document.candForm.sector.selectedIndex==0) {
	alert("<?php echo JText::_('RAM_JSSECTORERROR'); ?>");
	return false;
}

return true;

}

//-->
</script>

<?php
	} else { // they are a client!
		echo "<p class='error'>".JText::_('RAM_REGASCLIENT')."</p>\n";
	} // eof check for client record

	} else { // they are not logged in!
		echo "<p class='error'>".JText::_('RAM_NOTLOGGEDIN')."</p>\n";
	} // eof check for user logged in
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&task=&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
	_myfooter($show_poweredby);

  } // eof function

//
// Client Details function
//
  function myclientdetails() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$notify_email = $params->get('notify_email', ''); // default is none
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_MYDETAILS'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
	$myemail=$user->get('email');

?>


<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting

	// check the user is logged in!
	if ($myuid > 0) {

	// see if a candidate record exists for this client
	$query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a candidate record, create a client one
	if ($num_rows==0) {
		// see if a client record exists for this client (if not one already)
		$query="select * from ".$dbprefix."ram_clients where userid='$myuid' ";
		$sth=mysql_query($query);
		$num_rows = mysql_num_rows($sth);
		// if there is NOT a client record, create one
		if ($num_rows==0) {
			$query2="insert into ".$dbprefix."ram_clients (userid, clientname, email) values ('$myuid', '$myrealname', '$myemail')";
			$sth2=mysql_query($query2);
			// check for any error
			if (mysql_error()) { // check for problem
				echo "<p class='error'><b>Error creating client record:</b> </p>\n" . mysql_error();
			} else {
//				echo "<p>Client record with id '$myuid' created OK.</p>\n";
			}
		}
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_CLIENTDETSHEAD'); ?></h2>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="<?php echo JRoute::_( "index.php?option=com_recruitmentmanager&task=&Itemid=$Itemid" ); ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
	// see if candidate form submitted
	if (isset($_POST["submit"])) {
		// yes, so get the form values
		$clientname=JRequest::getVar('clientname', '' ,"POST", 'STRING');
		$sector=JRequest::getVar('sector', '' ,"POST", 'STRING');
		$area=JRequest::getVar('area', '' ,"POST", 'STRING');
		$address1=JRequest::getVar('address1', '' ,"POST", 'STRING');
		$address2=JRequest::getVar('address2', '' ,"POST", 'STRING');
		$postcode=JRequest::getVar('postcode', '' ,"POST", 'STRING');
		$contactname=JRequest::getVar('contactname', '' ,"POST", 'STRING');
		$telephone=JRequest::getVar('telephone', '' ,"POST", 'STRING');
		$email=JRequest::getVar('email', '' ,"POST", 'STRING');

		$clientid = JRequest::getVar('clientid', '0' ,"POST", 'INTEGER');

		// and update the database
		$query="update ".$dbprefix."ram_clients set clientname='" . addslashes($clientname) . "', address1='" . addslashes($address1) . "', address2='" . addslashes($address2) . "', postcode='" . addslashes($postcode) . "', contactname='" . addslashes($contactname) . "', telephone='" . addslashes($telephone) . "', email='" . addslashes($email) . "', sector='$sector', area='$area' where id='$clientid' ";
		$sth=mysql_query($query);
		// check for any error
		if (mysql_error()) { // check for problem
			echo "<p><b>".JText::_('RAM_CLIENTSAVEERROR').":</b> </p>\n" . mysql_error();
		} else {
			echo "<p class='RAM_Para'>".JText::_('RAM_CLIENT')." '$clientname' ".JText::_('RAM_CLIENTSAVEMSG')."</p>\n";
			// agency email notification
			$header="From: noreply@".str_replace('www.', '', $_SERVER["HTTP_HOST"])."\r\n";
			$header.="Content-Type: text/plain; charset='utf-8'\r\n";
			$message=JText::_('RAM_CLIENTNAME') . ": $clientname\n\n" . JText::_('RAM_CLIENTADDR1') . ": $address1\n\n" . JText::_('RAM_CLIENTADDR2') . ": $address2\n\n" . JText::_('RAM_CLIENTPCODE') . ": $postcode\n\n" . JText::_('RAM_CLIENTCONTACT') . ": $contactname\n\n" . JText::_('RAM_CLIENTTELNO') . ": $telephone\n\n" . JText::_('RAM_EMAIL') . ": $email\n\n";

			$subject=JText::_('RAM_CLIENTMAILMSG3');

			// only send nofification if email address supplied
			if ($notify_email!='') {
				$res=mail($notify_email, $subject, $message, $header);
				if ($res) {
//					echo "	<p>Email notification sent to $notify_email.</p>";
				} else {
?>

	<p class='error'><?php echo JText::_('RAM_EMAILERROR'); ?></p>

<?php
				}
			} // eof check for email address

		} // eof check for any error

	} // eof submit check

	// now get the (possibly updated) client details
	$query="select * from ".$dbprefix."ram_clients where userid='$myuid' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a record, display error
	if ($num_rows==0) {
		echo "<p class='error'>".JText::_('RAM_CLIENTNOTFOUND')." '</p>\n";
	} else {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$clientid=$row['id'];
		$clientname=$row['clientname'];
		$sector=$row['sector'];
		$area=$row['area'];
		$address1=$row['address1'];
		$address2=$row['address2'];
		$postcode=$row['postcode'];
		$contactname=$row['contactname'];
		$telephone=$row['telephone'];
		$email=$row['email'];
	}
?>

<form action="index.php" onsubmit="return checkForm()" method="post" enctype="multipart/form-data" name="clientForm">

<input name="task" type="hidden" id="task" value="myclientdetails" />
<input type="hidden" name="option" value="com_recruitmentmanager" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

<table align="center" border="0" width="100%" cellpadding="5" cellspacing="5">
<tr><th class="tablehead" colspan="2"><?php echo JText::_('RAM_CLIENTCOMP'); ?></th></tr>
<tr>
	<td class="rowcolor2" width="25%"><b><?php echo JText::_('RAM_CLIENTNAME'); ?>:</b></td>
	<td class="rowcolor2" width="75%">
		<input type="text" name="clientname" value="<?php echo $clientname; ?>" size="30" />
	</td>
</tr><tr>
	<td class="rowcolor1"><?php echo JText::_('RAM_CLIENTADDR1'); ?>:</b> </td>
	<td class="rowcolor1" width="75%">
		<input type="text" name="address1" value="<?php echo $address1; ?>" size="50" />
	</td>
</tr><tr>
	<td class="rowcolor2"><?php echo JText::_('RAM_CLIENTADDR2'); ?>:</b> </td>
	<td class="rowcolor2" width="75%">
		<input type="text" name="address2" value="<?php echo $address2; ?>" size="50" />
	</td>
</tr><tr>
	<td class="rowcolor1"><?php echo JText::_('RAM_CLIENTPCODE'); ?>:</b> </td>
	<td class="rowcolor1" width="75%">
		<input type="text" name="postcode" value="<?php echo $postcode; ?>" size="10" />
	</td>
</tr><tr>
	<td class="rowcolor2"><?php echo JText::_('RAM_CLIENTCONTACT'); ?>:</b> </td>
	<td class="rowcolor2" width="75%">
		<input type="text" name="contactname" value="<?php echo $contactname; ?>" size="30" />
	</td>
</tr><tr>
	<td class="rowcolor1"><?php echo JText::_('RAM_CLIENTTELNO'); ?>:</b> </td>
	<td class="rowcolor1" width="75%">
		<input type="text" name="telephone" value="<?php echo $telephone; ?>" size="10" />
	</td>
</tr><tr>
	<td class="rowcolor2"><?php echo JText::_('RAM_EMAIL'); ?>:</b> </td>
	<td class="rowcolor2" width="75%">
		<input type="text" name="email" value="<?php echo $email; ?>" size="30" />
	</td>
</tr><tr>
	<td class="rowcolor1"><?php echo JText::_('RAM_SECTOR'); ?>:</b> </td>
	<td class="rowcolor1" width="75%">
	<select name="sector">
          <option value=""   <?php if ($sector==='') { echo 'selected'; } ?> ><?php echo JText::_('RAM_SELECTSECTOR'); ?></option>
<?php
	// get list of sectors
	$query="select * from ".$dbprefix."ram_sectors order by `desc` asc";
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		// read thru the records (now in an array)
		$rownum=0;
//		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
		while ($row=$sth[$rownum]) {
			$sid=$row['id'];
			$desc=$row['desc'];
			$selind='';
			if ($sector==$sid) { $selind='selected'; }
			echo "<option value='$sid' $selind >$desc</option>";
			$rownum++; // go to the next record
		} // eof while loop
	} // eof check for records found
?>
	</select>
</td>
</tr><tr>
	<td class="rowcolor2"><?php echo JText::_('RAM_AREA'); ?>:</b> </td>
	<td class="rowcolor2" width="75%">
	<select name="area">
          <option value=""   <?php if ($area==='') { echo 'selected'; } ?> ><?php echo JText::_('RAM_SELECTAREA'); ?></option>
<?php
	// get list of areas
	$query="select * from ".$dbprefix."ram_areas order by Country, County asc";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$aid=$row['id'];
			$Country=$row['Country'];
			$County=$row['County'];
			$selind='';
			if ($area==$aid) { $selind='selected'; }
			echo "<option value='$aid' $selind >$Country, $County</option>";
		} // eof while loop
	} // eof check for records found
?>
	</select>
	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">
		<input type="hidden" name="clientid" value="<?php echo $clientid; ?>" />
		<input type="reset" value="<?php echo JText::_('RAM_RESET'); ?>" name="reset" />
		<input type="submit" value="<?php echo JText::_('RAM_SAVEDETS'); ?>" name="submit" />
	</td>
</tr></table>

</form>

<script>
<!--

// validate form fields before submitting
function checkForm() {

if (document.clientForm.clientname.value=='') {
	alert("<?php echo JText::_('RAM_JSCLIENTNAMEERROR'); ?>");
	return false;
}

if (document.clientForm.area.selectedIndex==0) {
	alert("<?php echo JText::_('RAM_JSAREAERROR'); ?>");
	return false;
}

if (document.clientForm.sector.selectedIndex==0) {
	alert("<?php echo JText::_('RAM_JSSECTORERROR'); ?>");
	return false;
}

return true;

}

//-->
</script>

<?php
	} else { // they are a candidate!
		echo "<p class='error'>".JText::_('RAM_REGASCAND')."</p>\n";
	} // eof check for candidate record

	} else { // they are not logged in!
		echo "<p class='error'>".JText::_('RAM_NOTLOGGEDIN')."</p>\n";
	} // eof check for user logged in
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&task=&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
	_myfooter($show_poweredby);

  } // eof function


//
// function to display the details of a job
//
  function display() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_JOBDETAILS'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
?>
<div class="article">
<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting

	$jid = JRequest::getVar('jid', '0' ,"REQUEST", 'INTEGER');

	$query="select * from ".$dbprefix."ram_jobs where id = '$jid' ";
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		// get sector details
		$query2="select * from ".$dbprefix."ram_sectors  WHERE id = '".$row['sector']."' ";
//		$sth2=mysql_query($query2);
		$db->setQuery( $query2 ); // for Joomfish!
		$sth2 = $db->loadAssocList(); // for Joomfish!
		$num_rows2 = count($sth2); //	$num_rows2 = mysql_num_rows($sth2);
		// record found?
		if ($num_rows2>0) {
//			$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
			$row2=$sth2[0]; // get the record details (now in an array)
			$Sector=$row2['desc'];
		} else {
			$Sector=JText::_('RAM_SECTOR') . ' ' . JText::_('RAM_NOTFOUND');
		} // eof check for record found
		// get area details
		$query2="select * from ".$dbprefix."ram_areas WHERE id = '".$row['area']."' ";
		$sth2=mysql_query($query2);
		$num_rows2 = mysql_num_rows($sth2);
		// record found?
		if ($num_rows2>0) {
			$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
			$Country=$row2['Country'];
			$County=$row2['County'];
			$Area="$Country, $County";
		} else {
			$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
		} // eof check for record found
		// get rate band details
		$query2="select * from ".$dbprefix."ram_ratebands  WHERE id = '".$row['salaryrange']."' ";
		$sth2=mysql_query($query2);
		$num_rows2 = mysql_num_rows($sth2);
		// record found?
		if ($num_rows2>0) {
			$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
			$RateBand=$row2['desc'];
		} else {
			$RateBand=JText::_('RAM_RATEBAND') . ' ' . JText::_('RAM_NOTFOUND');
		} // eof check for record found

		$tmp='';
		if ($row['jobtype']==='1') { $tmp=JText::_('RAM_JOBTYPE1'); }
		if ($row['jobtype']==='2') { $tmp=JText::_('RAM_JOBTYPE2'); }
		if ($row['jobtype']==='3') { $tmp=JText::_('RAM_JOBTYPE3'); }
		if ($row['jobtype']==='4') { $tmp=JText::_('RAM_JOBTYPE4'); }
?>

	<h1 class="vacancy-name"><?php echo $row['jobtitle']; ?></h1>
	<dl>
		<dt><?php echo JText::_('RAM_JOBREF'); ?></dt>
		<dd>: <?php echo $row['jobref']; ?></dd>
		<dt><?php echo JText::_('RAM_SECTOR'); ?></dt>
		<dd>: <?php echo $Sector; ?></dd>
		<dt><?php echo JText::_('RAM_AREA'); ?></dt>
		<dd>: <?php echo $Area; ?></dd>
		<dt><?php echo JText::_('RAM_SALARYRANGE'); ?></dt>
		<dd>: <?php if ($show_ratebands): echo $RateBand; endif;?></dd>
		<dt><?php echo JText::_('RAM_JOBTYPELABEL'); ?></dt>
		<dd>: <?php echo $tmp; ?></dd>
	</dl>
	<h4><?php echo JText::_('RAM_JOBDESCLABEL'); ?></h4>

	<?php echo $row['jobdesc']; ?>

	<?php 
		$isSearch = JRequest::getVar('search', '' ,"REQUEST");
		if($isSearch) $taskSearch = '&task=search';
		$urlApply = JRoute::_( "index.php?option=com_recruitmentmanager&task=apply&action=apply&jid=" . $row['id'] ."&Itemid=". $Itemid);
		$urlBack = JRoute::_( "index.php?option=com_recruitmentmanager".$taskSearch."&Itemid=". $Itemid);
	?>
	<div align="center">
		<input class="bt-apply" type="button" name="apply" value="<?php echo  JText::_('RAM_JOBAPPLYMSG');?>" onclick="location.href='<?php echo $urlApply?>'"> 
		<input class="bt-apply" type="button" name="apply" value="Back" onclick="location.href='<?php echo $urlBack?>'">
	</div>
<?php } else { ?>

	<hr />
	<p class='RAM_Para'><?php echo JText::_('RAM_JOBNOTFOUND'); ?></p>

<?php
	}
?>

</div>
<?php

	_myfooter($show_poweredby);

  } // eof function

//
// function to display the details of a candidate
//
  function canddisplay() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_CANDDETSHEAD'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
?>

	<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_CANDDETSHEAD'); ?></h2>

	<p class='RAM_Para'><?php echo JText::_('RAM_CANDSUMMARY'); ?></p>

	<hr />

<?php
	$cid = JRequest::getVar('cid', '0' ,"REQUEST", 'INTEGER');

	$query="select * from ".$dbprefix."ram_candidates where id=$cid";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a record, display error
	if ($num_rows==0) {
		echo "<p class='error'>".JText::_('RAM_CANDNOTFOUND')."</p>\n";
	} else {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$firstname=$row['firstname'];
		$surname=$row['surname'];
		$cv_area=$row['area'];
		$cv_dob=$row['birthdate'];
		$cv_education=$row['education'];
		$cv_workexp=$row['experience'];
		$cv_feducation=$row['courses'];
		$cv_interests=$row['interests'];
		$cv_name=$row['cvurl'];
		$sector=$row['sector'];
?>

<p class='RAM_Para'><b><?php echo JText::_('RAM_NAME'); ?>:</b> <?php echo "$firstname  $surname"; ?><p>

<p class='RAM_Para'><b><?php echo JText::_('RAM_AREA'); ?>: </b>
<?php
	// get list of areas
	$query="select * from ".$dbprefix."ram_areas WHERE id = '$cv_area' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$Country=$row['Country'];
			$County=$row['County'];
			echo "$Country, $County";
		} // eof while loop
	} // eof check for records found
?>
</p>

<p class='RAM_Para'><b><?php echo JText::_('RAM_CANDSECTOR'); ?>: </b>
<?php
	// get list of sectors
	$query="select * from ".$dbprefix."ram_sectors WHERE id = '$sector' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$desc=$row['desc'];
			echo "$desc";
		} // eof while loop
	} // eof check for records found
?>
</p>

<p class='RAM_Para'>
<b><?php echo JText::_('RAM_CANDEDUC'); ?>:</b><br />
<?php echo $cv_education; ?>
</p>

<p class='RAM_Para'>
<b><?php echo JText::_('RAM_CANDWORKEXP'); ?>:</b><br />
<?php echo $cv_workexp; ?>
</p>

<p class='RAM_Para'>
<b><?php echo JText::_('RAM_CANDFE'); ?>:</b><br />
<?php echo $cv_feducation; ?>
</p>

<?php
	}
?>

	<hr />

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php

	_myfooter($show_poweredby);

  } // eof function

//
// function to search for candidates
//
  function candsearch() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_CANDSEARCHHEAD'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
?>

	<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_CANDSEARCHHEAD'); ?></h2>

	<p class='RAM_Para'><?php echo JText::_('RAM_CANDSEARCHINTRO'); ?></p>

	<hr />

<?php
	$filtersql = '';
	$searchtext = JRequest::getVar('searchtext', '' ,"POST", 'STRING');
	// have we been passed some search text?
	if ($searchtext!='') {
		echo "<p class='RAM_Para'><b>" . JText::_('RAM_CANDSEARCHEDFOR') . ":-</b> $searchtext</p>\n";
		if ($filtersql=='') {
			$filtersql = " WHERE (experience LIKE '%$searchtext%' OR keywords LIKE '%$searchtext%') ";
		} else {
			$filtersql .= " AND (experience LIKE '%$searchtext%' OR keywords LIKE '%$searchtext%') ";
		}
	} // eof check for search text
?>

<table align='center' cellspacing='1' cellpadding='0'>
<thead>
  <tr>
    <th class='tablehead'><?php echo JText::_('RAM_NAME'); ?></th>
    <th class='tablehead'><?php echo JText::_('RAM_AREA'); ?></th>
    <th class='tablehead'><?php echo JText::_('RAM_SECTOR'); ?></th>
    <th class='tablehead'><?php echo JText::_('RAM_CANDSEARCH_KWS'); ?></th>
  </tr>
</thead>
<tbody>
<?php
	$query="select * from ".$dbprefix."ram_candidates $filtersql order by surname, firstname asc";
	$sth=mysql_query($query) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	$rowcolor='even';
	// if there is NOT a record, display error
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$firstname=$row['firstname'];
			$surname=$row['surname'];
			$cv_area=$row['area'];
			$sector=$row['sector'];
			$keywords=$row['keywords'];

			// get area details
			$query2="select * from ".$dbprefix."ram_areas where id = '$cv_area' ";
			$sth2=mysql_query($query2) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$Country=$row2['Country'];
				$County=$row2['County'];
				$cv_area =  "$Country, $County";
			} else {
				$cv_area =  "Area not found!";
			} // eof check for record found

			// get sector details
			$query2="select * from ".$dbprefix."ram_sectors where id = '$sector' ";
			$sth2=mysql_query($query2) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$desc=$row2['desc'];
				$sector =  "$desc";
			} else {
				$sector =  "Sector not found!";
			} // eof check for record found

			$link = JRoute::_( 'index.php?option=com_recruitmentmanager&task=canddisplay&cid='. $row['id'] . "&Itemid=" . $Itemid );
?>
	<tr class='<?php echo $rowcolor; ?>'>
		<td><a href="<?php echo $link; ?>" target="_blank"><?php echo $firstname . ' ' . $surname; ?></a></td>
		<td><?php echo $cv_area; ?></td>
		<td><?php echo $sector; ?></td>
		<td><?php echo $keywords; ?></td>
	</tr>
<?php
			if ($rowcolor==='even') { $rowcolor='odd'; } else { $rowcolor='even'; }

		} // eof while

	} else {
?>
	<tr>
	<td colspan='4' class='<?php echo $rowcolor; ?>'><?php echo JText::_('RAM_CANDSEARCH_NONEFOUND'); ?></td>
	</tr>
<?php
	} // eof check for records
?>
</tbody>
</table>

</form>

	<hr />

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php

	_myfooter($show_poweredby);

  } // eof function


//
// function to display the details of a client
//
  function clientdisplay() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_CLIENTDETSHEAD'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
?>

	<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_CLIENTDETSHEAD'); ?></h2>

	<p class='RAM_Para'><?php echo JText::_('RAM_CLIENTSUMMARY'); ?></p>

	<hr />

<?php
	$cid = JRequest::getVar('clientid', '0' ,"REQUEST", 'INTEGER');

	$query="select * from ".$dbprefix."ram_clients where id=$cid";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a record, display error
	if ($num_rows==0) {
		echo "<p class='error'>".JText::_('RAM_CLIENTNOTFOUND')."</p>\n";
	} else {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$clientname=$row['clientname'];
		$sector=$row['sector'];
		$area=$row['area'];
		$address1=$row['address1'];
		$address2=$row['address2'];
		$postcode=$row['postcode'];
		$contactname=$row['contactname'];
		$telephone=$row['telephone'];
		$email=$row['email'];
?>

<p class='RAM_Para'><b><?php echo JText::_('RAM_NAME'); ?>:</b> <?php echo "$clientname"; ?><p>

<p class='RAM_Para'><b><?php echo JText::_('RAM_AREA'); ?>: </b>
<?php
	// get list of areas
	$query="select * from ".$dbprefix."ram_areas WHERE id = '$area' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$Country=$row['Country'];
			$County=$row['County'];
			echo "$Country, $County";
		} // eof while loop
	} // eof check for records found
?>
</p>

<p class='RAM_Para'><b><?php echo JText::_('RAM_SECTOR'); ?>: </b>
<?php
	// get list of sectors
	$query="select * from ".$dbprefix."ram_sectors WHERE id = '$sector' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$desc=$row['desc'];
			echo "$desc";
		} // eof while loop
	} // eof check for records found
?>
</p>

<?php
	}
?>

	<hr />

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php

	_myfooter($show_poweredby);

  } // eof function


//
// function to apply for a job
//
  function apply() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$notify_email = $params->get('notify_email', ''); // default is none
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_APPLYHEAD'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');

?>

<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting
?>

	<div class="article">
		<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_APPLYHEAD'); ?></h2>

<?php
	//
	// apply form submitted? (non-registered user job application)
	//
	if (isset($_POST['apply'])) {
		$firstname=JRequest::getVar('firstname', '' ,"POST", 'STRING');
		$surname=JRequest::getVar('surname', '' ,"POST", 'STRING');
		$name=$firstname . ' ' . $surname;
		$jobref=JRequest::getVar('jobref', '' ,"POST", 'STRING');
		$jobtitle=JRequest::getVar('jobtitle', '' ,"POST", 'STRING');
		$phone=JRequest::getVar('phone', '' ,"POST", 'STRING');
		$email=JRequest::getVar('email', '' ,"POST", 'STRING');
		$msg=JRequest::getVar('message', '' ,"POST", 'STRING');
		$comp=JRequest::getVar('jobcomp', '' ,"POST", 'STRING');
		$cons=JRequest::getVar('jobcons', '' ,"POST", 'STRING');
		$jid = JRequest::getVar('jid', '0' ,"REQUEST", 'INTEGER');
		$uid = JRequest::getVar('uid', '0' ,"REQUEST", 'INTEGER');

		// get the company/client details
		$query="select * from ".$dbprefix."ram_clients where id='$comp' ";
		$sth=mysql_query($query) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query);
		$num_rows = mysql_num_rows($sth);
		// if there is NOT a record, display error
		if ($num_rows==0) {
			$clientname='Unknown company!';
			$comp_email='';
		} else {
			$row=mysql_fetch_array($sth, MYSQL_ASSOC);
			$clientname=$row['clientname'];
			$comp_email=$row['email'];
		}

		$header="From: noreply@".str_replace('www.', '', $_SERVER["HTTP_HOST"])."\r\n";
		$header.="MIME-Version: 1.0\r\n";
		$header.="Content-Type: multipart/mixed; boundary=\"JMRAM-12345\"; charset='utf-8';\r\n";
		$header.="Content-Transfer-Encoding: 7bit\r\n";
		$header .= JText::_('RAM_MAILUPGRADE') . "\r\n";
		$message="--JMRAM-12345\r\n";
		$message.="Content-Type: text/plain;\r\n";
		$message.="Content-Transfer-Encoding: 7bit\r\n";
		$message.="\r\n" . JText::_('RAM_CANDMAILMSG3') . "\n\n" . JText::_('RAM_CANDMAILMSG1') . ":- '$name'. " . JText::_('RAM_CANDMAILMSG4') . "\n\n" . JText::_('RAM_CANDMAILMSG5') . ":- $jobref ($jobtitle)\n\n" . JText::_('RAM_COMPANY') . ": $clientname " . JText::_('RAM_CONSULTANT') . ": $cons\n\n" . JText::_('RAM_NAME') . ": $firstname $surname \n" . JText::_('RAM_PHONENUM') . ": $phone \n" . JText::_('RAM_EMAIL') . ": $email \n" . JText::_('RAM_MESSAGE') . ": $msg\r\n";
		// check for attachment (cv)
		if (isset($_FILES['cv']['name'])) {
		   if ($_FILES['cv']['name']!=='') {
			$cv_name=$_FILES['cv']['name']; // store for later
			$tmp = strtolower($cv_name);
			// check valid file type
			if ( (strpos($tmp, 'odt')) or (strpos($tmp, 'doc')) or (strpos($tmp, 'rtf')) or (strpos($tmp, 'pdf')) or (strpos($tmp, 'txt')) ) {
				// add seperator
				$message.="--JMRAM-12345\r\n";
				// get the attachment data and encode it
				$fd=fopen ($_FILES['cv']['tmp_name'], "r");
				$FileContent=fread($fd,filesize($_FILES['cv']['tmp_name']));
				fclose ($fd);
				$att=chunk_split(base64_encode($FileContent));
				$message.="Content-Type: " . $_FILES['cv']['type'] . "; name=\"" . $_FILES['cv']['name'] . "\"\r\n";
				$message.="Content-Transfer-Encoding: base64\r\n";
				$message.="Content-Disposition: attachment\r\n";
				$message.= "\r\n";
				$message.="$att\r\n"; // attachment data
				$message.= "\r\n\r\n";
				$message.="--JMRAM-12345--\r\n";
				//
				// now copy it to the server for storage (New at 1.5.2)
				// first, create cvs folder if it doesn't exist
				$cvfolder = dirname(__FILE__)."/cvs";
//				echo "<p>cvfolder = $cvfolder</p>\n"; // debugging only
				if (!file_exists($cvfolder)) {
					$res=mkdir($cvfolder, 0777);
				} else {
					$res=chmod($cvfolder, 0777);
				}
				// now create users folder if it doesn't exist
				$userfolder = "$cvfolder/$myuid";
//				echo "<p>userfolder = $userfolder</p>\n"; // debugging only
				if (!file_exists($userfolder)) {
					$res=mkdir($userfolder, 0777);
				} else {
					$res=chmod($userfolder, 0777);
				}
				// now build the filename and MOVE it to it's destination
				$uploadfile = "$userfolder/$cv_name";
				if (move_uploaded_file($_FILES["cv"]['tmp_name'], $uploadfile)) {
//					echo "<p>Stored uploaded file to:- $uploadfile</p>\n"; // debugging only
					echo "<p class='RAM_Para'>" . JText::_('RAM_CVUPLOADED') . "</p>\n";
					// finally, create an application record (with a 0 userid)
					$cdate=date("Y-m-d"); // format the current date
					$query="insert into ".$dbprefix."ram_applications (jobid, userid, date, cvurl, `status` ) values ('$jid', '$uid', '$cdate', '$cv_name', '1')";
					$sth=mysql_query($query);
				}

			} else {
				$att=''; // invalid type
				echo "<p class='error'>" . JText::_('RAM_INVFILETYPE') . ":- " . $_FILES['cv']['type'] . ". " . JText::_('RAM_IGNORED') . "</p>\n";
			} // eof check for valid file type

		   } else {
			$att='';
			$message.="--JMRAM-12345--\r\n";
		   } // eof check for non null filename

		} else {
			$att='';
			$message.="--JMRAM-12345--\r\n";
		} // eof check for attachment

		$subject=JText::_('RAM_CANDMAILSUBJECT2');

		// only send nofification if email address supplied
		if ($notify_email!='') {
			$res=mail($notify_email, $subject, $message, $header);
			// check for error
			if ($res) {
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_INTEREST'); ?></p>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
			} else {
?>

	<p class='error'><?php echo JText::_('RAM_APPLYERROR'); ?></p>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
			} // eof check for error

		} // eof check for email address

		// now see if client should be nofified too
		if ($allow_client_jobmgt) {
			// only send nofification if email address supplied
			if ($comp_email!='') {
				$res=mail($comp_email, $subject, $message, $header);
				// check for error
				if ($res) {
				} else {
				} // eof check for error
			} // eof check for email address
		} // eof check for client nofification

	} // eof check for form submitted

	$jid = JRequest::getVar('jid', '0' ,"REQUEST", 'INTEGER');
	$uid = JRequest::getVar('uid', '0' ,"REQUEST", 'INTEGER');

//	echo "<p>jid = $jid, uid = $uid</p>\n"; // debugging only

	// check for valid user id
	if ($uid=='0') {
		// non-registered user
		$query="select * from ".$dbprefix."ram_jobs where id = '$jid' ";
//		$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
		$db->setQuery( $query ); // for Joomfish!
		$sth = $db->loadAssocList(); // for Joomfish!
		$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
		if ($num_rows>0) {
//			$row=mysql_fetch_array($sth, MYSQL_ASSOC);
			$row=$sth[0]; // get the record details (now in an array)
?>

	
		<dl>	
			<dt><b><?php echo JText::_('RAM_JOBREF'); ?>:</b></dt>
			<dd><?php echo $row['jobref'];?></dd>

			<dt><b><?php echo JText::_('RAM_JOBTITLE'); ?>:</b></dt>
			<dd><?php echo $row['jobtitle']; ?></dd>

<?php
			// get sector details
			$query2="select * from ".$dbprefix."ram_sectors  WHERE id = '".$row['sector']."' ";
//			$sth2=mysql_query($query2);
			$db->setQuery( $query2 ); // for Joomfish!
			$sth2 = $db->loadAssocList(); // for Joomfish!
			$num_rows2 = count($sth2); //	$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
//				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$row2=$sth2[0]; // get the record details (now in an array)
				$Sector=$row2['desc'];
			} else {
				$Sector=JText::_('RAM_SECTOR') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found
			// get area details
			$query2="select * from ".$dbprefix."ram_areas WHERE id = '".$row['area']."' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$Country=$row2['Country'];
				$County=$row2['County'];
				$Area="$Country, $County";
			} else {
				$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found
			// get rate band details
			$query2="select * from ".$dbprefix."ram_ratebands  WHERE id = '".$row['salaryrange']."' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$RateBand=$row2['desc'];
			} else {
				$RateBand=JText::_('RAM_RATEBAND') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found

			$tmp='';
			if ($row['jobtype']==='1') { $tmp=JText::_('RAM_JOBTYPE1'); }
			if ($row['jobtype']==='2') { $tmp=JText::_('RAM_JOBTYPE2'); }
			if ($row['jobtype']==='3') { $tmp=JText::_('RAM_JOBTYPE3'); }
			if ($row['jobtype']==='4') { $tmp=JText::_('RAM_JOBTYPE4'); }
?>

			<dt><b><?php echo JText::_('RAM_SECTOR'); ?>:</b></dt>
			<dd><?php echo $Sector; ?></dd>

			<dt><b><?php echo JText::_('RAM_AREA'); ?>:</b></dt>
			<dd><?php echo $Area; ?></dd>

<?php
		if ($show_ratebands) { // see if should show the rate bands
?>
			<dt><b><?php echo JText::_('RAM_SALARYRANGE'); ?>:</b></dt>
			<dd><?php echo $RateBand; ?></dd>
<?php
		} // eof rate band check
?>

			<dt><b><?php echo JText::_('RAM_JOBTYPELABEL'); ?>:</b></dt>
			<dd><?php echo $tmp; ?></dd>
		</dl>
		<br>
		<h4><?php echo JText::_('RAM_JOBDESCLABEL'); ?>:</h4>
		<?php echo $row['jobdesc']; ?>
	</div>

	<p class='RAM_Para'><b><?php echo JText::_('RAM_PLEASE'); ?></b></p>

	<form class="apply-form" action="index.php" onsubmit="return checkForm()" method="post" enctype="multipart/form-data" name="applyForm">

	<input name="jid" type="hidden" id="jid" value="<?php echo $jid; ?>" />
	<input name="uid" type="hidden" id="uid" value="<?php echo $uid; ?>" />
	<input name="Itemid" type="hidden" id="Itemid" value="<?php echo $Itemid; ?>" />

	<input name="task" type="hidden" id="task" value="apply" />
	<input type="hidden" name="option" value="com_recruitmentmanager" />

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_PERSHEAD'); ?></h2>

	<table>
	<tr>
		<td width="100"><b><?php echo JText::_('RAM_CANDFNAME'); ?>:</b></td>
		<td><input name="firstname" type="text" value="" size="25" maxlength="32" /></td>
	</tr><tr>
			<td><b><?php echo JText::_('RAM_CANDLNAME'); ?>:</b></td>
		<td><input name="surname" type="text" value="" size="25" maxlength="32" /></td>
	</tr><tr>
		<td><b><?php echo JText::_('RAM_EMAIL'); ?>:</b></td>
	`	<td><input type="text" name="email" value="" size="35" maxlength="60" /></td>
	</tr><tr>
		<td><b><?php echo JText::_('RAM_CANDMOBILE'); ?>:</b></td>
		<td><input type="text" name="phone" value="" size="15" maxlength="20" /></td>
	</tr><tr>
		<td><b><?php echo JText::_('RAM_MESSAGE'); ?>:</b></td>
		<td>
			<textarea name="message" wrap="physical" rows="4" cols="50" placeholder="<?php echo JText::_('RAM_PLEASECONTACT'); ?>"></textarea>
		</td>
	</tr><tr>
		<td colspan='2'>

			<p class='RAM_Para'><b><?php echo JText::_('RAM_CVHELP2'); ?></b></p>

			<p class='RAM_Para'><b><?php echo JText::_('RAM_CVSUPP'); ?></p>

		</td>
	</tr><tr>
		<td><p class='RAM_Para'><b><?php echo JText::_('RAM_CHOOSE'); ?>:</b></td>
		<td><input type="file" name="cv" /></p></td>
	</tr><tr>
		<td colspan="2">
			<input type='hidden' name='jobref' value='<?php echo $row['jobref']; ?>' />
			<input type='hidden' name='jobtitle' value='<?php echo $row['jobtitle']; ?>' />
			<input type='hidden' name='jobcomp' value='<?php echo $row['company']; ?>' />
			<input type='hidden' name='jobcons' value='<?php echo $row['consultant']; ?>' />

			<input type="reset" value="Clear Form" name="reset" />
			<input type="submit" value="Apply Now" name="apply" />
		</td>
	</tr>
	</table>

<script language="JavaScript">
<!--

// validate form fields before submitting
function checkForm() {

	if (document.applyForm.firstname.value=='') {
		alert("<?php echo JText::_('RAM_JSFNERROR'); ?>");
		return false;
	}

	if (document.applyForm.surname.value=='') {
		alert("<?php echo JText::_('RAM_JSSNERROR'); ?>");
		return false;
	}

	if (document.applyForm.email.value=='') {
		alert("<?php echo JText::_('RAM_JSEMAILERROR'); ?>");
		return false;
	}

	if ((document.applyForm.email.value != '') && 	(document.applyForm.email.value.search(/([^\'\.\@\-0-9a-zA-Z])/)!=-1))  {
		alert("<?php echo JText::_('RAM_JSEMAILERROR2'); ?>");
		return false;
	}

	if (document.applyForm.phone.value=='') {
		alert("<?php echo JText::_('RAM_JSPHONEERROR'); ?>");
		return false;
	}

	return true;

}

//-->
</script>

	</form>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="<?php echo JRoute::_('index.php?option=com_recruitmentmanager&task=search&Itemid=18');?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php

		} else {
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_CLOSED'); ?></p>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
		}

	} else { // registered user

		$cdate=date("Y-m-d"); // format the current date
		$query="insert into ".$dbprefix."ram_applications (jobid, userid, date, `status`) values ('$jid', '$uid', '$cdate', '1')";
		$sth=mysql_query($query);
		// confirm record creation/update
		$query="select id from ".$dbprefix."ram_applications where jobid='$jid' and userid='$uid' ";
		$sth=mysql_query($query);
		$num_rows = mysql_num_rows($sth);
		$status='';
		// if there is NOT a record, display error
		if ($num_rows==0) {
			echo "<p class='error'>" . JText::_('RAM_APPSAVEERROR') . "</p>\n";
		} else {
			$row=mysql_fetch_array($sth, MYSQL_ASSOC);
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_APPLYHELP1'); ?></p>

	<p class='RAM_Para'><?php echo JText::_('RAM_APPLYHELP2'); ?></p>

<?php
//			echo "<p>The application details have been saved.</p>\n";
			// send the admin an email notification of this application
			// first get the job details
			$query2="select * from ".$dbprefix."ram_jobs where id='$jid' ";
			//print "<p>SQL: $query2</p>\n";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$jobref=$row2['jobref'];
				$jobtitle=$row2['jobtitle'];
				$comp=$row2['company'];
				$cons=$row2['consultant'];
			} else {
				$jobref='';
				$jobtitle=JText::_('RAM_CLOSED');
				$comp=JText::_('RAM_CLOSED');
				$cons=JText::_('RAM_CLOSED');
			}
			// get the company/client details
			$query2="select * from ".$dbprefix."ram_clients where id='$comp' ";
			$sth2=mysql_query($query2) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query2);
			$num_rows2 = mysql_num_rows($sth2);
			// if there is NOT a record, display error
			if ($num_rows2==0) {
				$clientname='Unknown company!';
				$comp_email='';
			} else {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$clientname=$row2['clientname'];
				$comp_email=$row2['email'];
			}
			// get the users details
			$query2="select * from ".$dbprefix."ram_candidates where userid='$uid' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			if ($num_rows2==0) {
				$name=JText::_('RAM_CANDNOTFOUND');
			} else {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$name=$row2['firstname'] . ' ' . $row2['surname'];
			}
			$header="From: noreply@".str_replace('www.', '', $_SERVER["HTTP_HOST"])."\r\n";
			$header.="Content-Type: text/plain; charset='utf-8'\r\n";
			$message=JText::_('RAM_CANDMAILMSG3') . ":- '$name'. \n\n" . JText::_('RAM_CANDMAILMSG6') . ":- $jobref ($jobtitle)\n\n" . JText::_('RAM_COMPANY') . ": $clientname " . JText::_('RAM_CONSULTANT') . ": $cons\n\n";

			$subject=JText::_('RAM_CANDMAILSUBJECT2');

			// only send nofification if email address supplied
			if ($notify_email!='') {
				$res=mail($notify_email, $subject, $message, $header);
				if ($res) {
//					echo "	<p>Email notification sent to $notify_email.</p>";
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
				} else {
?>

	<p class='error'><?php echo JText::_('RAM_EMAILERROR'); ?></p>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
				}
			} // eof check for email address

			// now see if client should be nofified too
			if ($allow_client_jobmgt) {
				// only send nofification if email address supplied
				if ($comp_email!='') {
					$res=mail($comp_email, $subject, $message, $header);
					// check for error
					if ($res) {
					} else {
					} // eof check for error
				} // eof check for email address
			} // eof check for client nofification

		} // eof check for record creation

	} // eof uid check

	_myfooter($show_poweredby);

  } // eof function


//
// function to allow a client to insert a job
//
  function jobinsert() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$notify_email = $params->get('notify_email', ''); // default is none
	$bonus_mandatory = $params->get('bonus_mandatory', '0'); // default is no
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_SUBMITJOBHEAD'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');

?>

	<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting

	// see if a candidate record exists for this client
	$query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a candidate record, they are a client so show the form, etc.
	if ($num_rows==0) {
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_SUBMITJOBHEAD'); ?></h2>

<?php
	// has the job form been submitted?
	if (isset($_POST['jobref'])) {
		$jobref=JRequest::getVar('jobref', '' ,"POST", 'STRING' );
		$sector=JRequest::getVar('sector', '' ,"POST", 'STRING' );
		$area=JRequest::getVar('area', '' ,"POST", 'STRING' );
		$range=JRequest::getVar('salary', '' ,"POST", 'STRING' );
		$jobtype=JRequest::getVar('jobtype', '' ,"POST", 'STRING' );
		$jobtitle=JRequest::getVar('jobtitle', '' ,"POST", 'STRING' );
		$jobdesc=JRequest::getVar('jobdesc', '' ,"POST", 'STRING', 4 );
		$company=JRequest::getVar('company', '' ,"POST", 'STRING' );

		// get the company/client details
		$query="select * from ".$dbprefix."ram_clients where id='$company' ";
		$sth=mysql_query($query) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query);
		$num_rows = mysql_num_rows($sth);
		// if there is NOT a record, display error
		if ($num_rows==0) {
			$clientname='Unknown company!';
			$comp_email='';
		} else {
			$row=mysql_fetch_array($sth, MYSQL_ASSOC);
			$clientname=$row['clientname'];
			$comp_email=$row['email'];
		}

		$area_desc=JRequest::getVar('area_desc', '' ,"POST", 'STRING' );
		$sector_desc=JRequest::getVar('sector_desc', '' ,"POST", 'STRING' );
		$range_desc=JRequest::getVar('salary_desc', '' ,"POST", 'STRING' );
		$jobtype_desc=JRequest::getVar('jobtype_desc', '' ,"POST", 'STRING' );
		$jobtitle_desc=JRequest::getVar('jobtitle_desc', '' ,"POST", 'STRING' );

		$bonusdue=JRequest::getVar('bonusdue', '' ,"POST", 'STRING' );

		$dateposted=date('Y-m-d__h:m:s'); // get current date/time

		$query="insert into ".$dbprefix."ram_jobs ( jobref, sector, area, salaryrange, jobtype, jobtitle, jobdesc, company, dateposted, jobfilled, top5, bonusdue, submittedby ) values ( '" . addslashes($jobref) . "', '$sector', '$area', '$range', '$jobtype', '" . addslashes($jobtitle) . "', '" . addslashes($jobdesc) . "', '" . addslashes($company) . "', '$dateposted', 'n', 'n', '" . addslashes($bonusdue) . "', '$myuid' )";
		$sth=mysql_query($query);
		// check for any error
		if (mysql_error()) {
			echo "<p class='RAM_Para'><b>" . JText::_('RAM_JOBJOBSAVEMSG1') . ":</b> </p>\n" . mysql_error();
		} else {
			echo "<p class='RAM_Para'> " . JText::_('RAM_JOBJOBSAVEMSG2') . " '$jobtitle' " . JText::_('RAM_JOBJOBSAVEMSG3') . "</p>\n";
		}

		$header="From: noreply@".str_replace('www.', '', $_SERVER["HTTP_HOST"])."\r\n";
		$header.="MIME-Version: 1.0\r\n";
		$header.="Content-Type: multipart/mixed; boundary=\"JMRAM-12345\"; charset='utf-8'\r\n";
		$header.="Content-Transfer-Encoding: 7bit\r\n";
		$header .= JText::_('RAM_MAILUPGRADE') . "\r\n";
		$message="--JMRAM-12345\r\n";
		$message.="Content-Type: text/plain; charset='utf-8'\r\n";
		$message.="Content-Transfer-Encoding: 7bit\r\n";
		$message.="\r\n" . JText::_('RAM_CLIENTMAILMSG2') . ":-\n\n" . JText::_('RAM_JOBREF') . " / " . JText::_('RAM_JOBTITLE') . ": $jobref ($jobtitle)\n\n" . JText::_('RAM_COMPANY') . ": $clientname\n\n" . JText::_('RAM_SECTOR') . ": $sector_desc \n" . JText::_('RAM_AREA') . ": $area_desc \n" . JText::_('RAM_SALARYRANGE') . ": $range_desc \n" . JText::_('RAM_JOBTYPELABEL') . ": $jobtype_desc \n\n" . JText::_('RAM_JOBDESCLABEL') . ": $jobdesc\r\n";
		// check for attachment (cv)
		if (isset($_FILES['cv']['name'])) {
		   if ($_FILES['cv']['name']!=='') {
			$cv_name=$_FILES['cv']['name']; // store for later
			$tmp = strtolower($cv_name);
			// check valid file type
			if ( (strpos($tmp, 'odt')) or (strpos($tmp, 'doc')) or (strpos($tmp, 'rtf')) or (strpos($tmp, 'pdf')) or (strpos($tmp, 'txt')) ) {
				// add seperator
				$message.="--JMRAM-12345\r\n";
				// get the attachment data and encode it
				$fd=fopen ($_FILES['cv']['tmp_name'], "r");
				$FileContent=fread($fd,filesize($_FILES['cv']['tmp_name']));
				fclose ($fd);
				$att=chunk_split(base64_encode($FileContent));
				$message.="Content-Type: " . $_FILES['cv']['type'] . "; name=\"" . $_FILES['cv']['name'] . "\"\r\n";
				$message.="Content-Transfer-Encoding: base64\r\n";
				$message.="Content-Disposition: attachment\r\n";
				$message.= "\r\n";
				$message.="$att\r\n"; // attachment data
				$message.= "\r\n\r\n";
				$message.="--JMRAM-12345--\r\n";
			} else {
				$att=''; // invalid type
				echo "<p class='error'>" . JText::_('RAM_INVFILETYPE') . ":- " . $_FILES['cv']['type'] . ". " . JText::_('RAM_IGNORED') . "</p>\n";
			}
		   } else {
			$att='';
			$message.="--JMRAM-12345--\r\n";
		   }
		} else {
			$att='';
			$message.="--JMRAM-12345--\r\n";
		}

		$subject=JText::_('RAM_CLIENTMAILMSG');

		// only send nofification if email address supplied
		if ($notify_email!='') {
			$res=mail($notify_email, $subject, $message, $header);
			// check for error
			if ($res) {
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_JOBSUBMITTHANKS'); ?></p>

<?php
			} else {
?>

	<p class='error'><?php echo JText::_('RAM_SUBMITERROR'); ?></p>

<?php
			}
		} // eof check for email address


	} // eof check for form submitted
?>

<form action="index.php" onsubmit="return checkForm()" method="post" enctype="multipart/form-data" name="adminForm">

<input name="task" type="hidden" id="task" value="jobinsert" />
<input type="hidden" name="option" value="com_recruitmentmanager" />

<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

<table align="center" border="0" width="100%" cellpadding="5" cellspacing="5">
<tr><th class="tablehead" colspan="2"><?php echo JText::_('RAM_JOBDETAILS'); ?></th></tr>
<tr>
	<td class="rowcolor2" colspan="2">

	<b><?php echo JText::_('RAM_JOBREF'); ?>:</b> <input type="text" name="jobref" value="" size="10" />
	(<?php echo JText::_('RAM_JOBREFMSG'); ?>)

	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

	<b><?php echo JText::_('RAM_SECTOR'); ?>:</b> <select name="sector">
	<option value="" ><?php echo JText::_('RAM_SELECTSECTOR'); ?></option>
<?php
	// get list of sectors
	$query="select * from ".$dbprefix."ram_sectors order by `desc` asc";
//	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		// read thru the records (now in an array)
		$rownum=0;
//		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
		while ($row=$sth[$rownum]) {
			$sid=$row['id'];
			$desc=$row['desc'];
			echo "<option value='$sid'>$desc</option>";
			$rownum++; // go to the next record
		} // eof while loop
	} // eof check for records found
?>
	</select>

	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">

	<b><?php echo JText::_('RAM_AREA'); ?>:</b> <select name="area">
	<option value="" ><?php echo JText::_('RAM_SELECTAREA'); ?></option>
<?php
	// get list of areas
	$query="select * from ".$dbprefix."ram_areas order by Country, County asc";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$aid=$row['id'];
			$Country=$row['Country'];
			$County=$row['County'];
			echo "<option value='$aid'>$Country, $County</option>";
		} // eof while loop
	} // eof check for records found
?>
</select>

	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

	<b><?php echo JText::_('RAM_SALARYRANGE'); ?>:</b> <select name="salary">
	<option value="" ><?php echo JText::_('RAM_SELECTRANGE'); ?></option>
<?php
	// get list of rate bands
	$query="select * from ".$dbprefix."ram_ratebands order by `display_order`, `desc` asc";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$bid=$row['id'];
			$desc=$row['desc'];
			echo "<option value='$bid'>$desc</option>";
		} // eof while loop
	} // eof check for records found
?>
	</select>

	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">

	<b><?php echo JText::_('RAM_JOBTYPELABEL'); ?>:</b> <select name="jobtype">
          <option value="" ><?php echo JText::_('RAM_SELECTJOBTYPE'); ?></option>
          <option value="1" ><?php echo JText::_('RAM_JOBTYPE1'); ?></option>
          <option value="2" ><?php echo JText::_('RAM_JOBTYPE2'); ?></option>
          <option value="3" ><?php echo JText::_('RAM_JOBTYPE3'); ?></option>
          <option value="4" ><?php echo JText::_('RAM_JOBTYPE4'); ?></option>
    </select>

	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

	<b><?php echo JText::_('RAM_JOBTITLE'); ?>:</b> <input type="text" name="jobtitle" value="" size="40" />

	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">
	<b><?php echo JText::_('RAM_COMPANY'); ?>:</b> 
<?php
	// get client name
	$query="select * from ".$dbprefix."ram_clients WHERE userid = '$myuid' ";
	$sth=mysql_query($query) or die( JText::_('RAM_QUERYFAILED') . ': ' . mysql_error() . "<br />SQL = " . $query);
	$num_rows = mysql_num_rows($sth);
	// client record found?
	if ($num_rows>0) {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC); // yes
		$cid=$row['id'];
		$desc=$row['clientname'];
	} else { // no
		$cid='';
		$desc='Company not found!';
	} // eof check for client record found
?>
	<input type="hidden" name="company" value="<?php echo $cid; ?>" /><?php echo $desc; ?>
	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

	<b><?php echo JText::_('RAM_JOBDESCLABEL'); ?>:</b>

<?php
$editor =& JFactory::getEditor();
echo $editor->display('jobdesc', '', '450', '200', '40', '5', false);
?>
	<br />

	<p class='RAM_Para'>(<?php echo JText::_('RAM_JOBJOBDESCMSG'); ?>)</p>

	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">

	<p class='RAM_Para'><b><?php echo JText::_('RAM_JOBATTACHMENT'); ?></b></p>

	<p class='RAM_Para'><b><?php echo JText::_('RAM_CVSUPP'); ?></p>

	<p class='RAM_Para'><b><?php echo JText::_('RAM_CHOOSE'); ?>:</b> <input type="file" name="cv" /></p>

	</td>
</tr><tr>
	<td class="rowcolor1" colspan="2">

	<p class='RAM_Para'><b><?php echo JText::_('RAM_BONUS_DUE'); ?>:</b> <input type="text" name="bonusdue" value="" size="8" />	<?php echo '(' . JText::_('RAM_IFANY') . ')'; ?></p>

	</td>
</tr><tr>
	<td class="rowcolor2" colspan="2">

	<input type="hidden" name="uid" value="<?php echo $myuid; ?>" />

	<input type="hidden" name="area_desc" value="" />
	<input type="hidden" name="sector_desc" value="" />
	<input type="hidden" name="salary_desc" value="" />
	<input type="hidden" name="jobtype_desc" value="" />

	<input type="reset" value="<?php echo JText::_('RAM_CLEARFORM'); ?>" name="reset" />
	<input type="submit" value="<?php echo JText::_('RAM_SUBMITDETAILS'); ?>" name="submit" />

	</td>

</tr></table>

</form>

<script>
<!--

// validate form fields before submitting
function checkForm() {

	if (document.adminForm.sector.selectedIndex==0) {
		alert("<?php echo JText::_('RAM_JSSECTORERROR'); ?>");
		return false;
	}
	if (document.adminForm.area.selectedIndex==0) {
		alert("<?php echo JText::_('RAM_JSAREAERROR'); ?>");
		return false;
	}
	if (document.adminForm.salary.selectedIndex==0) {
		alert("<?php echo JText::_('RAM_JSRANGEERROR'); ?>");
		return false;
	}
	if (document.adminForm.jobtype.selectedIndex==0) {
		alert("<?php echo JText::_('RAM_JSJOBTYPEERROR'); ?>");
		return false;
	}
	if (document.adminForm.jobtitle.value=='') {
		alert("<?php echo JText::_('RAM_JSJOBTITLEERROR'); ?>");
		return false;
	}
	if ( (document.adminForm.jobdesc.value=='') && (document.adminForm.cv.value=='') ) {
		alert("<?php echo JText::_('RAM_JSJOBDESCERROR'); ?>");
		return false;
	}
<?php
	// force entry of the bonus field?
	if ($bonus_mandatory) {
?>
	if (document.adminForm.bonusdue.value=='') {
		alert("<?php echo JText::_('RAM_JSBONUSERROR'); ?>");
		return false;
	}
<?php
	} // eof check for bonus_mandatory field
?>

	// store the selected dropdown text values in variables for emailing
	document.adminForm.area_desc.value=document.adminForm.area.options[document.adminForm.area.selectedIndex].text;
	document.adminForm.sector_desc.value=document.adminForm.sector.options[document.adminForm.sector.selectedIndex].text;
	document.adminForm.salary_desc.value=document.adminForm.salary.options[document.adminForm.salary.selectedIndex].text;
	document.adminForm.jobtype_desc.value=document.adminForm.jobtype.options[document.adminForm.jobtype.selectedIndex].text;
	
return true;

}

//-->
</script>

<?php
	} else { // they are a candidate!
		echo "<p class='error'>".JText::_('RAM_REGASCAND2')."</p>\n";
	} // eof check for candidate record
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&task=&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
	_myfooter($show_poweredby);

  } // eof function


//
// function to allow a client to list any jobs they've submitted
//
  function jobslist() {

	_myheader();

	// get a parameter from the component's configuration
	$params = &JComponentHelper::getParams( 'com_recruitmentmanager' );
	$show_poweredby = $params->get('show_poweredby', 1); // default is show
	$show_greeting = $params->get('show_greeting', 1); // default is show
	$notify_email = $params->get('notify_email', ''); // default is none
	$bonus_mandatory = $params->get('bonus_mandatory', '0'); // default is no
	$show_ratebands = $params->get('show_ratebands', 1); // default is show
	$allow_client_jobmgt = $params->get('allow_client_jobmgt', 0); // default is no

	//set page title
	$document = &JFactory::getDocument();
	$document->setTitle(JText::_('RAM_PAGETITLE').' - '.JText::_('RAM_MYJOBDETAILS'));

	$Itemid = JRequest::getVar('Itemid', '' ,"REQUEST");
	$task 	= JRequest::getVar('task', '' ,"REQUEST");

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');
//	echo "<p>dbparams = $dbhost, $dbuser, $dbpassword, $dbname, $dbprefix</p>\n"; // debugging only

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get a handle for the std joomla DB connection (only so we can get data already translated by Joomfish!)
	$db =& JFactory::getDBO();

	// get our front_heading (New at 1.5.2. Used to be in global parameter.)
	$query="select * from ".$dbprefix."ram_frontpage ";
//	$sth=mysql_query($query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
//		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$row=$sth[0]; // get the record details (now in an array)
		$front_heading=$row['front_heading'];
	} else { // no record found, display errors!
		$front_heading='front_heading ' . JText::_('RAM_NOTFOUND');
	} // eof check for records found

	// ---------------- get the user details ---------------
	$user =& JFactory::getUser();
	$myrealname=$user->get('name');
	$myusername=$user->get('username');
	$myuid=$user->get('id');
?>

	<h1 class="RAM_Heading"><?php echo $front_heading; ?></h1>

<?php
	if ($show_greeting) {
		if ($myuid > 0) {
			echo "<p class='RAM_Greeting'><b>".JText::_('RAM_GREETING')."</b> $myrealname</p>\n";
		} // eof check for user logged in
	} // eof check for show_greeting

	// see if the client is updating any job statuses
	if ($task=='statusamend') {
		$upderror=0;
		echo "<p class='RAM_Para'>".JText::_('RAM_JOBSTATUSMSG1')."</p>\n"; // debugging only
		$jobid 	= JRequest::getVar('jobid', '' ,"REQUEST");
		// go thru the supplied job ids
		for ($n=0;$n<count($jobid);$n++) {
			$checked = JRequest::getVar('filled_'.$jobid[$n], '' ,"REQUEST");
			if ($checked=='on') { $filled='y'; } else { $filled='n'; }
//			echo "<p>jobid = $jobid[$n], filled = $filled</p>\n"; // debugging only
			// update the job status
			$query="UPDATE ".$dbprefix."ram_jobs SET jobfilled='$filled' where id = '" . $jobid[$n] . "' ";
//			echo "<p>SQL = $query</p>\n"; // debugging only
			$sth=mysql_query($query);
			// check for any error
			if (mysql_error()) {
				$upderror=1;
				echo "<p class='error'><b>".JText::_('RAM_JOBSTATUSMSG2').":</b> </p>\n" . mysql_error();
			}
		} // eof for loop

		if (!$upderror) { echo "<p class='RAM_Para'>".JText::_('RAM_JOBSTATUSMSG3')."</p>\n"; }

	} // eof job status update check

	// see if a candidate record exists for this client
	$query="select * from ".$dbprefix."ram_candidates where userid='$myuid'";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// if there is NOT a candidate record, they are a client so show the form, etc.
	if ($num_rows==0) {
		// get client details
		$query2="select * from ".$dbprefix."ram_clients WHERE userid = '$myuid' ";
		$sth2=mysql_query($query2) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query);
		$num_rows2 = mysql_num_rows($sth2);
		// client record found?
		if ($num_rows2>0) {
			$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
			$company=$row2['clientname'];
		} else {
			$company .= ' (Company record not found!)';
		} // eof check for client records found
?>

	<h2 class="RAM_SubHeading"><?php echo JText::_('RAM_MYJOBDETAILS'); ?></h2>

<p class='RAM_Para'><b><?php echo JText::_('RAM_COMPANY'); ?>:-</b> <?php echo $company; ?><p>

<form name="adminForm" method="post" action="index.php">

<input name="task" type="hidden" id="task" value="statusamend" />
<input type="hidden" name="option" value="com_recruitmentmanager" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

<table align="center" border="0" width="100%" cellpadding="0" cellspacing="1">
<thead>
  <tr>
    <th class="tablehead" width="90"><?php echo JText::_('RAM_JOBREF'); ?></th>
    <th class="tablehead"><?php echo JText::_('RAM_JOBTITLE') . ' / ' . JText::_('RAM_JOBTYPELABEL'); ?></th>
    <th class="tablehead"><?php echo JText::_('RAM_AREA'); ?></th>
    <th class="tablehead"><?php echo JText::_('RAM_SECTOR'); ?></th>
    <th class="tablehead" width="80"><?php echo JText::_('RAM_POSTED'); ?></th>
    <th class="tablehead" width="60"><?php echo JText::_('RAM_APPROVED'); ?></th>
    <th class="tablehead" width="40"><?php echo JText::_('RAM_FILLED'); ?></th>
  </tr>
</thead>
<tbody>
<?php
	// only list jobs submitted by the logged in user!
	$query="select * from ".$dbprefix."ram_jobs where submittedby='$myuid' order by dateposted desc";
//	$sth=mysql_query($query) or die("Query failed: " . mysql_error() . "<br />SQL = " . $query);
	$db->setQuery( $query ); // for Joomfish!
	$sth = $db->loadAssocList(); // for Joomfish!
	$num_rows = count($sth); //	$num_rows = mysql_num_rows($sth);
	// records found?
	if ($num_rows>0) {
		$rowclass='rowcolor2';
		// read thru the records (now in an array)
		$rownum=0;
//		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
		while ($row=$sth[$rownum]) {
			$jid=$row['id'];
			$company=$row['company'];
			$sector=$row['sector'];
			$area=$row['area'];
			$filled=$row['jobfilled'];
			$approved=$row['approved'];
			// get sector details
			$query2="select * from ".$dbprefix."ram_sectors  WHERE id = '$sector' ";
//			$sth2=mysql_query($query2);
			$db->setQuery( $query2 ); // for Joomfish!
			$sth2 = $db->loadAssocList(); // for Joomfish!
			$num_rows2 = count($sth2); // $num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
//				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$row2=$sth2[0]; // get the record details (now in an array)
				$Sector=$row2['desc'];
			} else {
				$Sector=JText::_('RAM_SECTOR') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found
			// get area details
			$query2="select * from ".$dbprefix."ram_areas WHERE id = '$area' ";
			$sth2=mysql_query($query2);
			$num_rows2 = mysql_num_rows($sth2);
			// record found?
			if ($num_rows2>0) {
				$row2=mysql_fetch_array($sth2, MYSQL_ASSOC);
				$Country=$row2['Country'];
				$County=$row2['County'];
				$Area="$Country, $County";
			} else {
				$Area=JText::_('RAM_AREA') . ' ' . JText::_('RAM_NOTFOUND');
			} // eof check for record found

			$link = JRoute::_( 'index.php?option=com_recruitmentmanager&task=display&jid='. $row['id'] . "&uid=$myuid&Itemid=$Itemid" );

			$tmp='';
			if ($row['jobtype']==='1') { $tmp=JText::_('RAM_JOBTYPE1'); }
			if ($row['jobtype']==='2') { $tmp=JText::_('RAM_JOBTYPE2'); }
			if ($row['jobtype']==='3') { $tmp=JText::_('RAM_JOBTYPE3'); }
			if ($row['jobtype']==='4') { $tmp=JText::_('RAM_JOBTYPE4'); }
?>
	<tr>
	<td class="<?php echo $rowclass; ?>" align="center"><a href="<?php echo $link; ?>" target="_blank"><?php echo $row['jobref']; ?></a></td>
	<td class="<?php echo $rowclass; ?>">
		<b><a href="<?php echo $link; ?>" target="_blank"><?php echo $row['jobtitle']; ?></a></b>
		<br />
		<?php echo $tmp; ?>
	</td>
	<td class="<?php echo $rowclass; ?>" align="center" width="40"><?php echo $Area; ?></td>
	<td class="<?php echo $rowclass; ?>" align="center" width="40"><?php echo $Sector; ?></td>
	<td class="<?php echo $rowclass; ?>" align="center" width="80"><?php echo $row['dateposted']; ?></td>
	<td class="<?php echo $rowclass; ?>" align="center" width="60"><?php echo $approved; ?></td>
	<td class="<?php echo $rowclass; ?>" align="center" width="40">
		<?php 
		$checked='';
		if ($filled=='y') { $checked='checked'; }
		// allow client to update job statuses?
		if ($allow_client_jobmgt) {
			echo "<input type='hidden' name='jobid[]' value='$jid' /><input type='checkbox' name='filled_$jid' $checked />\n"; // yes, display checkbox
		} else {
			echo "$filled"; // no, just display current status
		}
		?>
	</td>
	</tr>
<?php
			if ($rowclass=='rowcolor2') { $rowclass='rowcolor1'; } else { $rowclass='rowcolor2'; }

			$rownum++; // go to the next record

		} // eof while loop

	} // eof check for records
?>
</tbody>
</table>

<?php
	// only display button if allow_client_jobmgt is enabled!
	if ($allow_client_jobmgt) {
?>

<input type="submit" class="button" value="<?php echo JText::_('RAM_SAVEDETS'); ?>" />

<?php
	}
?>

</form>

<?php
	} else { // they are a candidate!
		echo "<p class='error'>".JText::_('RAM_REGASCAND2')."</p>\n";
	} // eof check for candidate record
?>

	<p class='RAM_Para'><?php echo JText::_('RAM_BACK'); ?> <a href="index.php?option=com_recruitmentmanager&task=&Itemid=<?php echo $Itemid; ?>"><?php echo JText::_('RAM_BACKLINK'); ?></a>.</p>

<?php
	_myfooter($show_poweredby);

  } // eof function




} // ------------------- eof class --------------------

//
// incorporate our style sheet
//
function _myheader() {
?>

<link rel="stylesheet" type="text/css" href="components/com_recruitmentmanager/recruitmentmanager.css" />

<?php

} // eof _myheader function

//
// display the page bottom, if any
//
function _myfooter($show_poweredby) {
	global $RecruitmentManagerVersion;

	if ($show_poweredby) {
?>

<p class="poweredby"><?php echo JText::_('RAM_POWERED_BY'); ?> <b>Joomla Recruitment Agency Manager</b> - <?php echo JText::_('RAM_VERSION'); ?> <?php echo $RecruitmentManagerVersion; ?></p>

<?php
	} // eof check for show_poweredby

} // eof _myfooter function

//
// function to generate a Captcha Code
//
function _generateCode($characters, $possible) {
	/* list all possible characters, similar looking characters and vowels have been removed */
	$code = '';
	$i = 0;
	while ($i < $characters) { 
		$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
		$i++;
	}
	return $code;
} //end _generateCode

?>
